How to invoke a user defined event in the controls of Gridview
=============================

1) In aspx Take a gridview having one of the template fields i.e Item Template as LinkButton

<asp:TemplateField HeaderText=”Folio No”>
<EditItemTemplate>
<asp:TextBox ID=”TextBox1″ runat=”server” Text='<%# Bind(“Folio_no”) %>’></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID=”Label2″ runat=”server” Text='<%# Bind(“Folio_no”) %>’ OnClick=”click” ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>

2) In Code-behind Page:

protected void click(object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;
GridViewRow gvr = (GridViewRow)lb.Parent.Parent;

LinkButton lnk_fno = (LinkButton)gvr.FindControl(“Label2”);
}

Advertisements