开发者

buttons and listviews

开发者 https://www.devze.com 2023-02-03 22:53 出处:网络
i have two listviews and each one contains an linkbutton. if i press the lb from the first listview it fires up an event but when i press the lb from the second one it dosen\'t. but if i put the lb ju

i have two listviews and each one contains an linkbutton. if i press the lb from the first listview it fires up an event but when i press the lb from the second one it dosen't. but if i put the lb just above the second listview it fires it up.

first listview:

<asp:ListView ID="ListViewMesaje" runat="server">
    <LayoutTemplate>
        <ul>
            <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
        </ul>
    </LayoutTemplate>
    <ItemTemplate>
        <asp:LinkButton ID="LinkButtonStergeMesaj" runat="server" CommandName="stergeMesaj"
                                        CommandArgument='<%#Container.DataItem%>' OnCommand="LinkButtonListView_Click"><div id="mesajdelete" class='<%#getBackgGifMesaj(getUsernameMesaj((string) Container.DataItem,"citit"))%>'></div></asp:LinkButton>
    </ItemTemplate>
</asp:List开发者_JAVA技巧View>

second one:

<asp:ListView ID="ListViewFriendRequests" runat="server" DataSourceID="SqlDataSourceFriendRequests" >
        <LayoutTemplate>
            <ul>
                <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
            </ul>
        </LayoutTemplate>
        <ItemTemplate>
            <asp:LinkButton ID="LinkButtonfqignora" runat="server" CommandName="refuzaPrieten"
                                        CommandArgument='<%#Eval("username")%>' OnCommand="LinkButtonListView_Click"><div id="friendreqign" >'<%#Eval("username")%>'</div></asp:LinkButton>
        </ItemTemplate>
</asp:ListView>


I finally found an answer why the buttons inside a listview don't get fired up. If your using an SqlDataSource as your DataSource you need to declare SelectCommand, UpdateCommand, DeleteCommand and InsertCommand for the sqldatasource, like this:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
                   ConnectionString="<%$ ConnectionStrings:Pubs %>"
                   SelectCommand="SELECT [au_id], [au_lname], [au_fname], [state] FROM [authors]"
                   UpdateCommand="UPDATE [authors] SET [au_id] = @au_id, [au_lname] = @au_lname,[au_fname] = @au_fname, [state] = @state WHERE [au_id] = @original_au_id"
                   DeleteCommand="DELETE FROM [authors] WHERE [au_id] = @original_au_id"/>

At first i just declared the SelectCommand, and that's why the buttons didn't got fired up.


Two suggestions: Have you tried removing the DataSourceID attribute, since that seems to be the main difference between the two?

Also, it's better to subscribe to the ListView's Command event instead of subscribing directly to the link button's command event. When the command even fires on the button, the event will bubble up and the listview will take it and fire its own event with the relevant info.

0

精彩评论

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

关注公众号