views:

199

answers:

2

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 ?

A: 

Why not just use item template?

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

// use
<asp:TemplateField>
<ItemTemplate>
    prefix <%# Eval("FieldName") %> suffix
</ItemTemplate>
</asp:TemplateField>
Wil
could i databind it ? this way wouldn't i need two columns ?
MarceloRamires
No, this should work as you suggested, the output would end up being stack overflow if overflow was the FieldsName
Wil
+1  A: 

Use a custom column.

  <asp:TemplateField HeaderText="MyColumn">
    <ItemTemplate> 
         stack <asp:Literal runat="server" Text="<%#Eval("myField")%>" />
    </ItemTemplate>
  </asp:TemplateField>  
Jan Jongboom
could i databind it ? how would i do it ?
MarceloRamires
what would exactly be this myfield ?
MarceloRamires
Replace your `<asp:BoundField>` with the above code. `myField` is the name of the column in your datatable.
Jan Jongboom