Marcelo
Marcelo

Reputation: 3391

Modify Asp gridview boundfield

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 ?

Upvotes: 3

Views: 4306

Answers (3)

Zo Has
Zo Has

Reputation: 13028

notice

HtmlEncode=false

<asp:BoundField DataField="yourColumn" HeaderText="Your Header" DataFormatString="{0} overflow" HtmlEncode="false" SortExpression="GenCommission" />

Upvotes: 1

Wil
Wil

Reputation: 2358

Why not just use item template?

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

// use
<asp:TemplateField>
<ItemTemplate>
    prefix <%# Eval("FieldName") %> suffix
</ItemTemplate>
</asp:TemplateField>

Upvotes: 0

Jan Jongboom
Jan Jongboom

Reputation: 27322

Use a custom column.

  <asp:TemplateField HeaderText="MyColumn">
    <ItemTemplate> 
         stack <asp:Literal runat="server" Text="<%#Eval("myField")%>" />
    </ItemTemplate>
  </asp:TemplateField>  

Upvotes: 3

Related Questions