Reputation: 1945
I'm in the process of debugging some old code that contains .aspx files and c# files for the code behind. I'm having some trouble figuring out how to bind the text in 'HeaderText' for a TemplateField. (Note: Never worked with aspx before). Basically I have an array of strings in the code-behind and a few different TemplateFields in the .aspx files. I want to bind the HeaderText of those fields to the strings. I know for TextBoxes it would be
Text = '<%# bindingStuffHere %>
As an example, say I have a template field like below:
<asp:TemplateField HeaderText="" >
And in the code behind I have:
String[] days = new String[5]
days[0] = "SAT"
I want to bind "SAT" to the HeaderText. The template is in a GridView.
Upvotes: 0
Views: 535
Reputation: 837
You can't bind HeaderText in asp:TemplateField. Instead you can implement OnRowDataBound event and change the header text there.
protected void gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Text = days[i];
}
}
}
Upvotes: 2