0

I have a GridView BoundField value that contains the user name, and in the database I have two user name one in English and the other one in Arabic, and I want to change the BoundField user name value according to the language, I tried using TemplateField with label but I cant assign label value and it gives this error message:

the name Label doesn't exist in the current context

aspx code:

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

aspx.cs code:

if (Convert.ToString(Session["lang"]) == "en")
{
Label.Text = reader["user_name_en"].ToString();
}
else
{
Label.Text = reader["user_name_ar"].ToString();
}
arater 2000
  • 143
  • 7

1 Answers1

0

First, naming label as Label is confusing. Label is a keyword. you can change it to something meaningful lblUser etc..

Also, you can use the following. here index refers to the index where the label appears in gridview column starting from 0.

if (e.Row.RowType == DataControlRowType.DataRow)
{
    Label lblGridView = e.Row.Cells[index].FindControl("Label") as Label;
    lblGridView.Text="assign values here";
}
Gauravsa
  • 6,330
  • 2
  • 21
  • 30