3

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 receive "house" i want to display "stack house"

is there a property to put text behind or after whatever comes in the boundfield ?

Marcelo
  • 3,371
  • 10
  • 45
  • 76
  • If your placement is conditional, it's likely you're going to end up putting something in the code behind anyway unless you keep your conditions extremely simple. – Joel Etherton Jan 18 '10 at 13:11

3 Answers3

3

Use a custom column.

  <asp:TemplateField HeaderText="MyColumn">
    <ItemTemplate> 
         stack <asp:Literal runat="server" Text="<%#Eval("myField")%>" />
    </ItemTemplate>
  </asp:TemplateField>  
Jan Jongboom
  • 26,598
  • 9
  • 83
  • 120
1

notice

HtmlEncode=false

<asp:BoundField DataField="yourColumn" HeaderText="Your Header" DataFormatString="{0} overflow" HtmlEncode="false" SortExpression="GenCommission" />
Zo Has
  • 12,599
  • 22
  • 87
  • 149
0

Why not just use item template?

// instead of 
<asP:BoundField DataField="FieldName" />

// use
<asp:TemplateField>
<ItemTemplate>
    prefix <%# Eval("FieldName") %> suffix
</ItemTemplate>
</asp:TemplateField>
Wil
  • 2,328
  • 2
  • 20
  • 27