Add text to a bound column

E

Eagle

How do I add text to a template column with a label; I want to add "Name: "
in front of the ClientName:

<asp:TemplateColumn HeaderText="Client">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.ClientName") %>' ID="Label2"></asp:Label><br>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.ClientCity") %>' ID="Label5"></asp:Label><br>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.ClientState") %>' ID="Label6"></asp:Label>
</ItemTemplate>

I've tried several ways and keep getting a "server tag not well formed":

<asp:Label runat="server" Text="Name: " & '<%# DataBinder.Eval(Container,
"DataItem.ClientName") %>' ID="Label2"></asp:Label><br>

<asp:Label runat="server" Text="Name: " + '<%# DataBinder.Eval(Container,
"DataItem.ClientName") %>' ID="Label2"></asp:Label><br>

Thanks for your help.
 
E

Elton W

You can process it in datagrid_ItemDataBound event:

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType
== ListItemType. AlternatingItem)
{
TableCell clientCell = e.Item.Cells[client_index];
clientCell.Text = "Name: " + clientCell.Text;
}


HTH

Elton Wang
-----Original Message-----
How do I add text to a template column with a label; I want to add "Name: "
in front of the ClientName:

<asp:TemplateColumn HeaderText="Client">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.ClientName") %>'
ID="Label2"> said:
<asp:Label runat="server" Text='<%# DataBinder.Eval (Container,
"DataItem.ClientCity") %>' ID="Label5"></asp:Label><br>
<asp:Label runat="server" Text='<%# DataBinder.Eval (Container,
"DataItem.ClientState") %>' ID="Label6"></asp:Label>
</ItemTemplate>

I've tried several ways and keep getting a "server tag not well formed":

<asp:Label runat="server" Text="Name: " & '<%# DataBinder.Eval(Container,
"DataItem.ClientName") %>'
 
E

Eagle

Well, no, I can't do it there, I need to do it in html, any other ideas?


Elton W said:
You can process it in datagrid_ItemDataBound event:

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType
== ListItemType. AlternatingItem)
{
TableCell clientCell = e.Item.Cells[client_index];
clientCell.Text = "Name: " + clientCell.Text;
}


HTH

Elton Wang
-----Original Message-----
How do I add text to a template column with a label; I want to add "Name: "
in front of the ClientName:

<asp:TemplateColumn HeaderText="Client">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.ClientName") %>'
ID="Label2"> said:
<asp:Label runat="server" Text='<%# DataBinder.Eval (Container,
"DataItem.ClientCity") %>' ID="Label5"></asp:Label><br>
<asp:Label runat="server" Text='<%# DataBinder.Eval (Container,
"DataItem.ClientState") %>' ID="Label6"></asp:Label>
</ItemTemplate>

I've tried several ways and keep getting a "server tag not well formed":

<asp:Label runat="server" Text="Name: " & '<%# DataBinder.Eval(Container,
"DataItem.ClientName") %>'
ID="Label2"> said:
<asp:Label runat="server" Text="Name: " + '<%# DataBinder.Eval(Container,
"DataItem.ClientName") %>'
ID="Label2"> said:
Thanks for your help.


.
 
E

EJD

Hi,
You can add multiple items to the ItemTemplate in a templated column.
So you could have for instance...

<asp:TemplateColumn HeaderText="Company">
<ItemTemplate>
<asp:Label id="Label2" runat="server">Client: </asp:Label>
<asp:LinkButton id=lBtnCompany runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.contact_name") %>'
CommandName="Transfer" CommandArgument='<%# DataBinder.Eval(Container,
"DataItem.org_id") %>'>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>

I don't know if there's a limit to the number of items you can put in
an ItemTemplate, but this might work for you...

HTH.
 

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,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top