The GridView is one of the most widely used controls in ASP.net 2.0, and almost all data operations require it, as we normally do, to edit, delete, select, and so on, but how do we do this if the customer has to raise a hyperlink by clicking a row or into a row edit state? Here is a method to implement this feature. It will allow you to click anywhere in the line to trigger the event you need.
First populate data for the GridView
private void Binddata ()
{
SqlConnection myconnection = new SqlConnection (ConnectionString);
SqlCommand mycommand = new SqlCommand ("SELECT * from Users", MyConnection);
SqlDataAdapter ad = new SqlDataAdapter (mycommand);
DataSet ds = new DataSet ();
Ad. Fill (DS);
Gridview1.datasource = ds;
Gridview1.databind ();
}
Next we give GridViewRow a click attribute in the Gridview_rowdatabound event
protected void GridView1_RowDataBound (object sender, GridViewRowEventArgs e)
{
String alertbox = "alert ('";
if (E.row.rowtype = = Datacontrolrowtype.datarow)
{
Alertbox + = E.row.rowindex;
Alertbox + = "')";
E.row.attributes.add ("onclick", Alertbox);
}
}
OK, very simple method, hope to be useful to you!