Columns of a column in a datagrid

I have a datagrid where a piece of text needs to span multiple columns. Here's an example of what I need.

Row # Image Title Price Date

1 xxx My Name $ 99 1/1/2009 xxx Detailed description here

2 xxx name 2 $ 99 1/1/2009 xxx
        xxx Another long description

Is something like this possible in Asp.Net using datagrid? Any suggestions on how to do this?

+2


source to share


2 answers


Instead, you might find it easier to use an ASP.Net relay and have multiple rows in the DataItem. This way you have complete control over the layout.

It is technically possible to use ASP.NET GridView for this, but I suspect it would not be the most elegant solution here. The GridView (and Datagrid) were designed out of the box for one row per DataItem.

Here is an ASP.Net example containing a relay that illustrates an approach that might work for you:



        <asp:Repeater ID="Repeater1" runat="server">
        <HeaderTemplate>
            <table>
        </HeaderTemplate>
        <tr>
            <th>
                Col 1
            </th>
            <th>
                Col 2
            </th>
            <th>
                Col 3
            </th>
        </tr>
        <ItemTemplate>
            <tr>
                <td>
                    <%# Eval("Field1") %>
                </td>
                <td>
                    <%# Eval("Field2") %>
                </td>
                <td>
                    <%# Eval("Field3") %>
                </td>
            </tr>
            <tr>
                <td>
                    <%# Eval("Field4") %>
                </td>
                <td colspan="2">
                    <%# Eval("Field5") %>
                </td>
            </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater>

      

Note that the ItemTemplate contains two rows of the HTML table, the second of which contains a td with a colspan of 2.

Hope it helps.

+1


source


Do you need to use DataGrid ?, I would suggest ListView . It has all the features you need and uses templates for complete control over the user interface.



+1


source







All Articles