0

I am using GridView in ASP.NET with C#. I am adding Templete Field Columns to GridView on Runtime, Columns are added successfully with the required text in rows. But after filling GridView perform any button click event controls from rows removes, in rows i have Literal and Textbox controls in Templete Field as a ItemTempete.....

Any Help...

Shahid Iqbal
  • 2,095
  • 8
  • 31
  • 51

1 Answers1

0
<asp:GridView runat="server" ID="gridView">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton runat="server" ID="lnkTest"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Then in your rowdatabound event you can find it and do whatever you want

void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Entity entity = e.Row.DataItem as Entity;

        LinkButton lnkTest = e.Row.FindControl("lnkTest") as LinkButton;
        lnkTest.CommandArgument = entity.ID.ToString();
        lnkTest.Text = entity.Name;
    }
}