Friday, March 6, 2009

How to select a row in a grid by clicking any where of that row

Here one more thing that i have faced in my way....that is How to select a row in a grid by clicking any where of that row....
Below is the sample grid view for that...



Then add this simple code on the RowDataBound event of that Grid

protected void grdPatient_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton _singleClickButton = (LinkButton)e.Row.Cells[0].FindControl("lnkName");

string _jsSingle = ClientScript.GetPostBackClientHyperlink(_singleClickButton, "");

e.Row.Attributes["onclick"] = _jsSingle;

}

}