c# - 按钮和 ListView

标签 c# asp.net

我有两个 ListView ,每个 ListView 都包含一个链接按钮。 如果我从第一个 ListView 中按磅,它会触发一个事件,但是当我从第二个 ListView 中按磅时,它不会。但如果我将 lb 放在第二个 ListView 的正上方,它就会启动。

第一个 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:ListView>

第二个:

<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>

最佳答案

我终于找到了为什么 ListView 中的按钮没有被激活的答案。 如果您使用 SqlDataSource 作为数据源,则需要为 sqldatasource 声明 SelectCommand、UpdateCommand、DeleteCommand 和 InsertCommand,如下所示:

<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"/>

起初我只是声明了 SelectCommand,这就是按钮没有被激活的原因。

关于c# - 按钮和 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4647504/

相关文章:

c# - 检查 Linq to Entity 中的 True 或 Null 值

c# - Automapper null 集合变空

c# - 在 C# 中检查图像是否为空白

asp.net - 运行时错误

javascript - 要再次显示该网页,Internet Explorer 需要重新发送

c# - 在 ASP.NET 中使用 C# 将字符串转换为日期让我有一个小时的约会。为什么?

c# - 关于错误记录

母版页 head 标签中的 Javascript

c# - 识别导致回发的控件

asp.net - 无法通过 SSL 访问网站