Dec
20
Written by:
Wil Dobson
12/20/2007 2:51 PM
TO SELECT A ROW ONCLICK:
Firstly, you will need to enable row selections for your datagrid. this will place the proper javascript in your page for what is to come. This will place a select button on your page, but you can convert that column into a template and make the linkbutton visible=false.
you need a OnRowCreated event handler, so add this to your gridview's source (OnRowCreated="GridView1_RowCreated") or just set up a handler through the gridviews Events Property window.
The event handler will look something like this:
int RowCount = 0;
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
// get the row index, add onclick attribute for javascript:__doPostBack('GridView1','Select$0')
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "javascript:__doPostBack('" + ((GridView)sender).ID + "','Select$" + (RowCount - 1).ToString() + "')");
e.Row.Attributes.Add("onmouseover", "JavaScript:this.style.cursor='hand';");
}
RowCount++;
}
Copyright ©2007 Wil Dobson
Tags: