четвер, 15 квітня 2010 р.

HOWTO: Select the row in GridView ASP.NET control

Як селектнути стрічку в ГрідВю?
Можна зробити щось таке:

В код-біхайнд обробити івент гріда RowDataBound :

grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
     e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.grid, "Select$" + e.Row.RowIndex);
}
}

або

grid_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{

  if (grid.EditIndex == -1) {
 
e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference((System.Web.UI.Control)sender, "Select$" + e.Row.RowIndex.ToString));
}
}

або

protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.DataItemIndex == -1)
return;

e.Row.Attributes.Add("onclick",
  this.GetPostBackClientEvent(grid, "Select$" + e.Row.RowIndex.ToString()));
}

Немає коментарів:

Дописати коментар