adding text to a bound field in a gridview

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>
 
M

Milosz Skalecki [MCAD]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top