C# 2个相同代码,1个韩元';行不通 问题是:
我迭代了两个网格控件,一个按预期运行,另一个不按预期运行。这些片段在两个单独的页面上 工作示例 下面的示例有大约10条数据,可以正常工作,并且在呈现页面时显示所有更改C# 2个相同代码,1个韩元';行不通 问题是:,c#,asp.net,gridview,linq-to-sql,C#,Asp.net,Gridview,Linq To Sql,我迭代了两个网格控件,一个按预期运行,另一个不按预期运行。这些片段在两个单独的页面上 工作示例 下面的示例有大约10条数据,可以正常工作,并且在呈现页面时显示所有更改 protected void LoadEmployeeAccess() { gridEmployeeAccess.DataSource = TAClass .GetAllEmployeesWithEmail2(Globals.EmpNo);
protected void LoadEmployeeAccess()
{
gridEmployeeAccess.DataSource = TAClass
.GetAllEmployeesWithEmail2(Globals.EmpNo);
gridEmployeeAccess.DataBind();
foreach (GridViewRow row in gridEmployeeAccess.Rows)
{
var targetControl = row.Cells[0].Controls[0];
Button btnEdit = targetControl.FindControl("btnEdit") as Button;
Label lblGroup = targetControl.FindControl("lblGroup") as Label;
Label lblRole = targetControl.FindControl("lblRole") as Label;
Label lblEmployeeNumber = targetControl
.FindControl("lblEmployeeNumber") as Label;
bool isAdmin = TAClass.CheckIfAdmin(Globals.EmpNo, lblGroup.Text);
if(isAdmin)
btnEdit.Visible = true;
}
}
非工作示例
不工作的代码只有两个样本数据,在第一次迭代中找到labelEditGroupName
fine,在第二次迭代中,我没有得到控件,但找到了btnEdit
protected void gridThreshold_RowEditing(object sender, GridViewEditEventArgs e)
{
gridThreshold.EditIndex = e.NewEditIndex;
gridThreshold.ShowFooter = false;
//LoadInventory();
gridThreshold.DataSource = TAClass.ThresholdList(Globals.EmpNo);
gridThreshold.DataBind();
GridViewRow item = gridThreshold.Rows[gridThreshold.EditIndex];
Button btnSave = (Button)item.FindControl("btnSave");
Button btnCancel = (Button)item.FindControl("btnCancel");
Label lblEditLimit = (Label)item.FindControl("lblEditLimit");
TextBox txtEditThreshold = (TextBox)item.FindControl("txtEditThreshold");
btnCancel.Visible = true;
btnSave.Visible = true;
lblEditLimit.Visible = true;
foreach (GridViewRow row2 in gridThreshold.Rows)
{
var targetControl = row2.Cells[0].Controls[0];
Button btnEdit = targetControl.FindControl("btnEdit") as Button;
Label lblEditGroupName = targetControl
.FindControl("lblEditGroupName") as Label;
bool isAdmin = TAClass.CheckIfAdmin(Globals.EmpNo, lblEditGroupName.Text);
btnEdit.Visible = isAdmin;
}
}
请帮助我知道哪里出了问题
提前谢谢 奇怪的事情确实发生在编译器中-从一个新手程序员的角度来看,这两个网格似乎有完全不同的数据源,那么它们到底是如何相同的呢?这些值包含哪些值?。在它们两个上都设置一个中断,并使用即时窗口确定问题所在;如果它没有爆炸,它可能工作正常,但你没有得到你所期望的数据。。。当我们无法访问您的数据时,无法真正帮助您解决可能与数据有关的问题。我没有说它们是相同的,我显示了它们具有相同的代码,如图所示。