C# 使用if语句更改GridView边界字段

C# 使用if语句更改GridView边界字段,c#,asp.net,gridview,C#,Asp.net,Gridview,我有一个包含用户名的GridView BoundField值,在数据库中我有两个用户名,一个是英文的,另一个是阿拉伯文的,我想根据语言更改BoundField用户名值,我尝试使用TemplateField with label,但我无法分配label值,它会给出以下错误消息: 当前上下文中不存在名称标签 aspx代码: <asp:TemplateField HeaderText="user name"> <ItemTemplate> <asp:Label ID='L

我有一个包含用户名的GridView BoundField值,在数据库中我有两个用户名,一个是英文的,另一个是阿拉伯文的,我想根据语言更改BoundField用户名值,我尝试使用TemplateField with label,但我无法分配label值,它会给出以下错误消息:

当前上下文中不存在名称标签

aspx代码:

<asp:TemplateField HeaderText="user name">
<ItemTemplate>
<asp:Label ID='Label' runat='server' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>

首先,将标签命名为标签容易混淆。标签是一个关键字。你可以把它改成有意义的东西

此外,您还可以使用以下命令。此处索引指标签从0开始出现在gridview列中的索引

if (e.Row.RowType == DataControlRowType.DataRow)
{
    Label lblGridView = e.Row.Cells[index].FindControl("Label") as Label;
    lblGridView.Text="assign values here";
}

我试过了,但没有赋值
if (e.Row.RowType == DataControlRowType.DataRow)
{
    Label lblGridView = e.Row.Cells[index].FindControl("Label") as Label;
    lblGridView.Text="assign values here";
}