ASP.net GridView - Use If-Statement in HeaderText property of BoundField
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!
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 = //...
精彩评论