Reputation: 344
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
Reputation: 7943
Do this:
<asp:Label runat="server" Text='<%# Eval("city").ToString() + "," + Eval("state").ToString() %> '></asp:Label>
Upvotes: 1