adding text to a bound field in a gridview

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I add static text to a bound field in a gridview? For instance, I
want the following label in a gridview to be displayed as
"Smith: Exempt"
"Jones: Exempt"
etc.
<asp:Label ID="Label1" runat="server" Text='<%# Bind("LastName")
%>'></asp:Label>
 
Hi there,

Two ways:

1. Set DataFormatString property, i.e:
<columns>
<asp:BoundField DataField="LastName" DataFormatString="{0}: Exempt"/>
</columns>

2. Use template field instead:
<columns>
<asp:TemplateField HeaderText="Whatever">
<ItemTemplate>
<%# Eval("LastName") %>: Exempt
</ItemTemplate>
</asp:TemplateField>
</columns>

Hope it helps
 
Back
Top