views:

98

answers:

2

Can I do something like this:

    <asp:BoundField DataField="Field1" 
HeaderText='<% IF(Eval("Field2").ToString().SubString(3,4).Equals("Text3"),"Text1","Text2") %>'
SortExpression="Field1" />

With the goal of having the header of Field1 be Text1 when the 4th-7th characters of Field2 = Text3 and Text2 otherwise?

I tried it and it just put "'<% IF(Eval("Field2").ToString().SubString(3,4).Equals("Text3"),"Text1","Text2") %>'" as the actual header string!

Thanks in advance!

+1  A: 

The Eval() statement has meaning only within a data-binding context. As you'll find if you used data binding syntax (<%# /*...*/ %>), the header text does not provide a data-binding context. After all, there's only one header for zero-to-many rows.

You can set header text imperatively from the code-behind:

myGrid.Columns[columnIndex].HeaderText = //...
kbrimington
Oh ya. Good point. That makes absolutly no sence to have the headertext dependent on the Eval(). Thanks for poaring the cold water on my head and waking me up. +1
kralco626
A: 

If-Else is not supported for Eval in gridview. You could write a (at least protected when calling from aspx) Codebehind function that returns the value or use Gridview.RowDataBound for that.

Tim Schmelter