我有一个两个网格视图通用的rowdatabound方法。此方法的部分任务是为网格视图的最后一列赋值。
网格视图是相同的,但是两个网格视图的值不同。所以我需要检查我是在给第一个网格视图签名,还是在另一个网格视图上签名。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//Here i need to check which gridview (Gridview1 or Gridview2)
if (e.Row.RowType == DataControlRowType.DataRow)
{
{
int CellValue = Convert.ToInt32(e.Row.Cells[0].Text);
if (CellValue == 1)
e.Row.Cells[7].Text = "" + patchWeekTwo[0] + "t";
else if (CellValue == 2)
e.Row.Cells[7].Text = "" + patchWeekTwo[1] + "t";
else if (CellValue == 3)
e.Row.Cells[7].Text = "" + patchWeekTwo[2] + "t";
else if (CellValue == 4)
e.Row.Cells[7].Text = "" + patchWeekTwo[3] + "t";
else
e.Row.Cells[7].Text = "" + patchWeekTwo[4] + "t";
}
}
}发布于 2012-09-03 03:46:46
您可以检查sender是GridView1还是GridView2
if( sender == GridView1 ){}
else{}请注意,只有在页面顶部声明了GridView1,而不是在它的某个childs NamingContainers中声明了它时,这才能起作用。然后你可以检查id:
var grid = (GridView)sender;
if( grid.Id == "GridView1" ){}
else{}发布于 2012-09-03 03:54:11
我想这个应该可以了
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridView gv = (GridView)sender;
if(gv.ID == "gv1")
//do this
else
//do that
}https://stackoverflow.com/questions/12239134
复制相似问题