user2146538
user2146538

Reputation: 344

DataView with combined fields

I have a DataView with columns specified and I would like to take two individual fields and combine them into one field, for example 'Columbus' and 'Ohio' and put them into one field that looks like 'Columbus, Ohio'.

<asp:GridView ID="gv" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:TemplateField>
            <HeaderTemplate></HeaderTemplate>
            <ItemTemplate>
                <asp:Label runat="server" Text='<%# Eval("city") %>'></asp:Label>
                <asp:Label runat="server" Text='<%# Eval("state") %> '></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

I get an error when I try to do something like:

Text='<%# Eval("city") %>' + ', ' + '<%# Eval("state") %>'

Upvotes: 0

Views: 104

Answers (1)

afzalulh
afzalulh

Reputation: 7943

Do this:

<asp:Label runat="server" Text='<%# Eval("city").ToString() + "," + Eval("state").ToString() %> '></asp:Label>

Upvotes: 1

Related Questions