Add text to a bound column

Discussion in 'ASP .Net Datagrid Control' started by Eagle, May 11, 2005.

  1. Eagle

    Eagle Guest

    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.
    Eagle, May 11, 2005
    #1
    1. Advertising

  2. Eagle

    Elton W Guest

    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"></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.
    >
    >
    >.
    >
    Elton W, May 11, 2005
    #2
    1. Advertising

  3. Eagle

    Eagle Guest

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


    "Elton W" <> wrote in message
    news:03ee01c5566b$fd779850$...
    > 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"></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.
    > >
    > >
    > >.
    > >
    Eagle, May 18, 2005
    #3
  4. Eagle

    EJD Guest

    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.
    EJD, May 22, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John E.
    Replies:
    3
    Views:
    4,460
    masoud bayan
    Mar 25, 2005
  2. sunil panda

    Lower bound & Upper bound

    sunil panda, Dec 25, 2003, in forum: Java
    Replies:
    9
    Views:
    7,236
    thushara wijeratna
    Oct 7, 2008
  3. Ravichandran Mahalingam

    Bound Column or Template Column (w dAdapater?) in DataGrid

    Ravichandran Mahalingam, Jan 9, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    220
    Ravichandran Mahalingam
    Jan 9, 2004
  4. John E.

    Move bound column to right of dynamic column in datagrid?

    John E., Mar 24, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    231
    Elton Wang
    Mar 28, 2005
  5. TS
    Replies:
    3
    Views:
    406
    Walter Wang [MSFT]
    Aug 16, 2007
Loading...

Share This Page