formatting data grid RRS feed

  • Question

  • User-578779873 posted

    Hello I hope there is an easy answer to this. I have a data grid that gets data from sql. I want to change how the columns are laid out. Attached is an example of what I would like to do. Any help would be appreciated. Thank you

    Thursday, July 13, 2017 4:30 AM

All replies

  • User-1716253493 posted

    Afaik,  you can use TemplateField, you can design your own headertemplate, itemtemtemplate, edititemtemplate, footertemplate etc

    Thursday, July 13, 2017 7:06 AM
  • User-271186128 posted

    Hi quar1nteen ,

    I suggest you use Repeater control. Then you could easily format the header and item as a custom table.
    Please see the example below:

               <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:TestDbConnectionString %>" SelectCommand="SELECT * FROM Info"/>
               <asp:Repeater ID="Repeater3" runat="server" DataSourceID="SqlDataSource4">
                       <table border="1">
                               <th>First Name</th>
                               <th rowspan="2">DOB</th>
                               <th rowspan="2">Age</th>
                               <th rowspan="2">Weight</th>
                               <th>Last Name</th>
                               <th>Phone Number</th>
                           <td><%# Eval("First Name") %></td>
                           <td rowspan="2"><%# string.Format("{0:d}", Eval("DOB"))%></td>
                           <td rowspan="2"><%# Eval("Age") %></td>
                           <td rowspan="2"><%# Eval("Weight") %></td>
                           <td><%# Eval("Address") %></td>
                           <td><%# Eval("Last Name") %></td>
                           <td><%# Eval("Phone Number") %></td>

    The SQL table as below:

    The result as below:

    Best regards,

    Friday, July 14, 2017 3:21 AM