Monday, August 29, 2011

How can I show multiple database columns in gridview databound column?


GridView BoundField can only bind to a single field. If you want to do this, you can do so by one of the following ways:
> use calculated column in your database query i.e. concatenate multiple columns to a single column. For example: Select housenumber+', '+street as Address from client
> use GridView TemplateField. You can bind individual template in a single TempalteField. Following code snippet shows the trick:

<asp:GridView ID="GridView1" runat="server">
        <asp:TemplateField HeaderText="Address">
                <%#Eval("housenumber")%>, <%#Eval("street")%>

No comments:

Post a Comment