1

I have this gridView:

<asp:GridView ItemType="WebUI.FeatureInfoArea.FeatureDesc" AutoGenerateColumns="false" ID="gvFeatList" runat="server" CssClass="table table-striped table-bordered table-hover pointer height-10">
    <Columns>
        <asp:TemplateField HeaderText="Title">
            <ItemTemplate>
                <%# Item.Title %>
                <span style="display: none;"><%# Item.UID %></span>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Tip">
            <ItemTemplate>
                <%# Item.Tip %>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Here is code that binds data to GridView control:

protected void Page_Load(object sender, EventArgs e)
{
    string alias_Title = blabla1;
    string alias_Tip = blabla2;

    var result = fim.getFeaturesList();
    gvFeatList.DataSource = result.featureDesc;
    gvFeatList.DataBind();
}

As you can see I have some property called featureDesc and I bind it to data source.

Also in Page_Load event I have two variables called alias_Title and alias_Tip.

I need to display alias_Title instead of Title and alias_Tip instead of Tip.

So my question is, how can I make HeaderText in TemplateFields to be displayed variable alias_Title and alias_Tip.

halfer
  • 19,824
  • 17
  • 99
  • 186
Michael
  • 13,950
  • 57
  • 145
  • 288
  • Hi Michael. We'd rather questions were as succinct as possible here. I'm a volunteer editor, and I help with tidying up questions and making them as readable as possible. Things like (advance) thanks and other expressions of appreciation are not necessary in questions - please try to omit them. Thanks! – halfer Aug 15 '18 at 10:37
  • I often post this advice, which gives a flavour of the brevity we like here: _Note we prefer a technical style of writing here. We gently discourage greetings, hope-you-can-helps, thanks, advance thanks, notes of appreciation, regards, kind regards, signatures, please-can-you-helps, chatty material and abbreviated txtspk, pleading, how long you've been stuck, voting advice, meta commentary, etc. Just explain your problem, and show what you've tried, what you expected, and what actually happened._ – halfer Aug 15 '18 at 10:38

1 Answers1

1

You can set the Text of a HeaderRow Cell after DataBind is called.

gvFeatList.DataBind();

gvFeatList.HeaderRow.Cells[0].Text = alias_Title;
gvFeatList.HeaderRow.Cells[1].Text = alias_Tip;
VDWWD
  • 35,079
  • 22
  • 62
  • 79