开发者

Access Listview instance from its DataSource c# class

I have a ListView into a webpage binded to a c# class datasource named CommentsDAO. This class has the methods to retreive or delete data from ListView. There is no problem to get the data but, in order to delete a row I need to get the selected row, but the ListView instance is not in the scope of its datasource. To delete rows I have a button (imgbtn1) next to each row with the "Delete" command.

<asp:ListView ID="ListView1" runat="server" DataSourceID="ObjectDataSource1">
                    <LayoutTemplate>
                        <div id="itemPlaceholderContainer" runat="server" style="">
                            <span id="itemPlaceholder" runat="server" />
                        </div>
                    </LayoutTemplate>
                    <ItemTemplate>
                        <span>
                            <asp:Label ID="Label1" Font-Size="Small" runat="server" Text='<%# Eval("User") %>' />
                            <table>
                                <tr>
                                    <td>
                                        <div style="border: 1px solid; background-color: #F0F8FF; padding: 10px; height: 50px;
                                            overflow: auto">
                                            <asp:Label ID="ComentLabel" runat="server" Text='<%# Eval("Coment") %>' />
                                        </div>
                                    </td>
                                    <td valign="top">
                                        <asp:ImageButton ID="imgbtn1" CommandName="Delete" runat="server" ImageUrl="~/trash16x16.gif" />
                                    </td>
                                </tr>
                            </table>
                            <br />
                        </span>
                    </ItemTemplate>
                </asp:ListView>

...

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="ModalPopupDemo.Comentario"
    SelectMethod="FindAll" TypeName="ModalPopupDemo.ComentarioDAO" DeleteMethod="Delete">
</asp:ObjectDataSource>

Overall I need the following:

- User can make comments (...)

- I have a listview with comments (strings) in vertical orientation.

- When a outter button is pressed a Jquery popup will appear with an wysiwyg editor.

- When this popup is closed i need to do a ajax call to the server passing the editor content and save it into a DataBase

- Then the listview have to be updated with the data entered by user in the popup (ajax).

- If the author of the comment is logged in, a delete icon have to appear next to the comment

- If clicked, the comment have to be removed by doing an ajax call, deleting from database and updating the listview.

Well, is the Listview the best suitable control to do it? Should I use html tables with jquery code?

Thanks for your patiences and help regards, ton开发者_开发问答i


If I'm understanding you correctly, you are trying to manipulate the ListView from a custom DataSource object that you created?

I'm going to take a stab in the dark here, but if you are trying to delete data from the DataSource via your delete method, you would need to rebind the ListView to reflect your changes. It sounds like you're looking to edit the ListView from within the DataSource, which would be kind of a backwards approach.

You might be able to achieve that by adding a ListViewObject property to your DataSource class and passing in the instance of the ListView, but it would be simpler to just edit the DataSource and rebind the ListView as needed.

For the delete button, use the CommandArgument to pass in the index of the item (or other identifier), and in the OnItemCommand event, retrieve the identifier from the CommandArgument and delete the item from your DataSource using the identifier. Once the item has been deleted from the DataSource, rebind the ListView.

Does that help, or am I misunderstanding your need?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜