Grid View Event Handling
How to create the Event inside a grid view using Link Button-
Steps-
1. Select the grid view > Edit column > select bound field [bound two column of grid view with the database table]
2. Select template field > Add some header text to it > go to source > drop down Link button > now the control will be added to your grid view.
Creating 'OnClick' Event-
Go to source > insert the 'onclick' Event in Link button's attribute > give any name to the Event like Send_click.
In Code Window-
protected void Send_click (object sender, EventArgs e)
{
// connection open code
string cs = @"Data Source=49.50.88.43;Initial Catalog=grkistdb;Persist Security Info=True;User ID=grkistuser;Password=q2oR5w_356";
cn = new SqlConnection(cs);
cn.Open();
// used to activate the link button
GridViewRow r1 = ((LinkButton)sender).NamingContainer as GridViewRow;
// finding the control
LinkButton l1 = (LinkButton) r1.FindControl("label_id");
}
note:- foreach loop is not used with NamingContainer.
Comments
Post a Comment