I want to add some text to a boundfield build in the code behind without writing any code in the code behind.
example I receive "overflow" in a specific field, and i'd like to display "stack overflow" and if i rec开发者_开发技巧eive "house" i want to display "stack house"
is there a property to put text behind or after whatever comes in the boundfield ?
Use a custom column.
<asp:TemplateField HeaderText="MyColumn">
<ItemTemplate>
stack <asp:Literal runat="server" Text="<%#Eval("myField")%>" />
</ItemTemplate>
</asp:TemplateField>
notice
HtmlEncode=false
<asp:BoundField DataField="yourColumn" HeaderText="Your Header" DataFormatString="{0} overflow" HtmlEncode="false" SortExpression="GenCommission" />
Why not just use item template?
// instead of
<asP:BoundField DataField="FieldName" />
// use
<asp:TemplateField>
<ItemTemplate>
prefix <%# Eval("FieldName") %> suffix
</ItemTemplate>
</asp:TemplateField>
精彩评论