DataGrid - How to set multiple datafields to a single bound column?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yumbelie
    New Member
    • Dec 2007
    • 9

    DataGrid - How to set multiple datafields to a single bound column?

    Hi,
    I want to set multiple datafields from a dataset to a single boundcolumn in my gridview, but I can't see any easy way to do this since the DataField property of the boundcolumn takes a single string that maps 1-to-1 to the relevant column in the dataset. I want to map three columns from my dataset to a single column in my DataGrid - is there any easy way I can do this, or am I going to have to get complicated?


    *Please ignore the indenting - seems to be formatting issues*
    Code:
    E.g. (Currently displays in datagrid like this:)
    Product Type Category Category 
    Apple Fruit Fruit&Veg Fruits 
     
    I want:
    Product Type Category
    Apple Fruit Fruit&Veg
    Fruit
    Last edited by DrBunchman; Jun 25 '08, 12:13 PM. Reason: Moved to .NET Forum - ASP Forum for Classic ASP only
  • kshnbd
    New Member
    • Jun 2008
    • 3

    #2
    To use multiple fields in a single gridview column you have to use templatefield. try this.

    Code:
    <asp:TemplateField HeaderText="Category">
    <EditItemTemplate>
         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
         <asp:Label ID="Label1" runat="server" Text='<%# Eval("field1") + ", " + Eval("field2") + ", " + Eval("field3")%>'></asp:Label>
    </asp:TemplateField>

    Regards,

    Free Online Diary

    Comment

    Working...