我已经与这个问题作斗争了好几个小时,并且真的可以使用一些帮助:-)
这是网格
<asp:GridView ID="annonceView" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="dataSourceAnnoncer">
<Columns>
<asp:BoundField DataField="Productname" HeaderText="Productname" />
<asp:buttonfield buttontype="Link" commandname="Delete" text="Delete"/>
<asp:TemplateField HeaderText="Administration">
<ItemTemplate>
<asp:LinkButton ID="lnkBtnDelete" runat="server" Text="Delete" CausesValidation="False" CommandName="Delete" OnClientClick="return confirm('Delete?')" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="dataSourceAnnoncer" runat="server" ContextTypeName="Namespcae.TheContext"
EnableDelete="True" TableName="Annoncer">
</asp:LinqDataSource>
单击按钮字段可以很好地删除记录。单击链接按钮不起作用。我收到回发,网格显示为空,并且没有删除任何记录。似乎是一个空的数据绑定。我试图为 LinkButton 创建一个自定义 OnClick、OnCommand 事件,但都没有被触发。OnRowCommand 也不会被触发。
我不在代码隐藏中手动 DataBind。