How can I created a row clickabe GridView?
-
In the
RowDataBound
event handler write:e.Row.Attributes.Add("onclick", script);
where 'script' is either some javascript for client-side action or if you implement the IPostBackEventHandler, it can be a postback event reference, for server-side processing.
-
In the
RowDataBound
event handler write:e.Row.Attributes.Add("onclick", script);
where 'script' is either some javascript for client-side action or if you implement the IPostBackEventHandler, it can be a postback event reference, for server-side processing.
-
The GridView's rows are not clickable by default. The only way to change that is to add javascript code for the onclick event to the rows. Even if you want to get the click event on the server because you need a postback to get to the server and you can only achieve is in javascript (at least in this scenario). So for server-side processing tha page needs to implement the
IPostBackEventHandler
interface add contain two method similiar to these:protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(this, e.Row.ClientID));
}public void RaisePostBackEvent(string eventArgument)
{
//the eventArgument will contain the ClientID of the row you clicked on, so you can
//identify the row, if needed
} -
The GridView's rows are not clickable by default. The only way to change that is to add javascript code for the onclick event to the rows. Even if you want to get the click event on the server because you need a postback to get to the server and you can only achieve is in javascript (at least in this scenario). So for server-side processing tha page needs to implement the
IPostBackEventHandler
interface add contain two method similiar to these:protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(this, e.Row.ClientID));
}public void RaisePostBackEvent(string eventArgument)
{
//the eventArgument will contain the ClientID of the row you clicked on, so you can
//identify the row, if needed
}