gpt4 book ai didi

c# - rowdatabound 中的 gridview id

转载 作者:行者123 更新时间:2023-12-02 05:31:57 24 4
gpt4 key购买 nike

我有一个 rowdatabound 方法,它对两个 gridviews 是通用的。此方法的部分任务是将值分配给 GridView 的最后一列。

gridviews是一样的,但是两个gridviews的值是不一样的。所以我需要检查我是否将 vaules 分配给第一个 gridview 或另一个。

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";
}
}
}

最佳答案

你可以检查senderGridView1还是GridView2:

if( sender == GridView1 ){}
else{}

请注意,这仅在 GridView1 声明在页面顶部而不是在其中一个子 NamingContainers 中时有效。然后你可以检查 id:

var grid = (GridView)sender;
if( grid.Id == "GridView1" ){}
else{}

关于c# - rowdatabound 中的 gridview id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12239134/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com