Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display multiple data fields in BoundField of Gridview

Tags:

c#

asp.net

I have an asp:GridView which is bound. Within this I have multiple columns, I'm trying to get the data from two database fields concatenated into one field.

How to do this?

Something like this?

asp:BoundField DataField="field1 + ' ' + field2" HeaderText="Status" SortExpression="info"
like image 612
andrew slaughter Avatar asked Feb 01 '12 14:02

andrew slaughter


People also ask

How show multiple values in GridView single column?

Answers. Use a TemplateField. In the ItemTemplate tag, you've to put html corresponding to your UI requirements. You can put 2 link buttons.

How to use TemplateField in GridView in ASP net?

Start by adding a new TemplateField to the GridView by clicking on the Edit Columns link in the GridView's smart tag and adding a new TemplateField. Container. DataItem returns a DataRowView object corresponding to the DataSource record bound to the GridViewRow . Its Row property returns the strongly-typed Northwind.

What is BoundField in GridView in asp net c#?

The BoundField class is used by data-bound controls (such as GridView and DetailsView) to display the value of a field as text. The BoundField object is displayed differently depending on the data-bound control in which it is used.

How to add TemplateField in GridView in ASP net c#?

My bind method Tables[0]. Columns) { TemplateField tField = new TemplateField(); tField. HeaderText = dc. ColumnName; GridView2.


1 Answers

Pretty sure you need to use a TemplateField instead of BoundField for this.

In your GridView Columns Block:

    <asp:TemplateField HeaderText="Name">
        <ItemTemplate>
            <%# Eval("FirstName") + " " + Eval("LastName")%>
        </ItemTemplate>
    </asp:TemplateField>
like image 79
pseudocoder Avatar answered Sep 22 '22 06:09

pseudocoder