How to call code behind function in aspx file in server tag

I have a TabPanel whose HeaderText property I want to set using the function behind the code for example.

<asp:TabPanel ID="id" runat="server" HeaderText='<%= String.Format("{0}","some text") %>'>  

I cannot put a function call between the start and end tags because it is a TabPanel, but when I do the above, I just get an empty title on the page. I also tried <% #%> (I'm not sure about the difference between the two). A.

String.Format is just an example, not the real function I'm trying to call.

+3
source share
2 answers

, , , , . , , . , HeaderText .

<%= ... %> <%# ... %>, :

<Columns>
    <asp:TemplateField>
        <ItemTemplate>
            <%# Eval("SomeValue") %>
        </ItemTemplate>
    </asp:TemplateField>
</Columns>

, . HeaderTemplate :

<Columns>
    <asp:TemplateField>
        <HeaderTemplate>
            <%# Eval("SomeHeaderValue") %>
        </HeaderTemplate>
        <ItemTemplate>
            <%# Eval("SomeValue") %>
        </ItemTemplate>
    </asp:TemplateField>
</Columns>    
+2

Try:

HeaderText='<%# TabPanel_HeaderText %>'

protected string TabPanel_HeaderText
{
    get { return String.Format("{0}","some text"); }
}
0

All Articles