Gridview buttonfield works LinkButton doesn't

Posted by Karsten on Stack Overflow See other posts from Stack Overflow or by Karsten
Published on 2010-04-07T14:07:35Z Indexed on 2010/04/07 14:13 UTC
Read the original article Hit count: 577

I've been fighting this problem for many hours now and could really use some help :-)

This is the grid

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

Clicking the buttonfield deletes the record just fine. Clicking the LinkButton doesn't work. I get a postback and the grid is shown as empty and no record is deleted. Seems like an empty databinding. I have tried to create a custom OnClick, OnCommand event for the LinkButton, but neither are fired. The OnRowCommand isn't fired either.

I don't manually DataBind in the codebehind.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about gridview