我有一个rowdatabound方法,对于两个网格视图是常见的。此方法的部分任务是将值分配给gridview的最后一列。
网格视图相同,但值与两个网格视图不同。所以我需要检查我是否将第一个网格视图或另一个网格视图中的vaules作为标记。
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";
}
}
}
答案 0 :(得分:1)
您可以查看sender
是GridView1
还是GridView2
:
if( sender == GridView1 ){}
else{}
请注意,这仅适用于在页面顶部声明GridView1
而不在其中一个子NamingContainers
中声明的情况。然后你可以查看id:
var grid = (GridView)sender;
if( grid.Id == "GridView1" ){}
else{}
答案 1 :(得分:1)
我认为应该这样做
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridView gv = (GridView)sender;
if(gv.ID == "gv1")
//do this
else
//do that
}