Reputation: 1
I am using a datagrid in which I want to display my last column in next line or row and the next row in grid will shift down.
Name Age Sex Subject
Mac 24 M English, Science Maths, Geography
Nan 29 F English, Science Maths, Geography
I want to display like this:
Name Age Sex
Mac 24 M
English, Science Maths, Geography
Nan 29 F
English, Science Maths, Geography
Thanks in advance
Upvotes: 0
Views: 355
Reputation: 394
If you are not married to a DataGrid then I would recommend looking into the repeater control or the ListView control. It will give you a lot more freedom and be much easier to understand later
If for some reason you have to use a DataGrid there this a way, but it is very very hacky, it will be much harder to under stand when you look at this in a week or two, and is not a good idea in general but it achieves your goal.
<asp:DataGrid ID="dg" ShowHeader="false" runat="server"
AutoGenerateColumns="false">
<Columns>
<asp:BoundColumn DataField="Name"></asp:BoundColumn>
<asp:BoundColumn DataField="Age"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<%# Eval("Sex") %></td>
</tr>
<tr>
<td colspan="3">
<%# Eval("Courses") %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
in the last column you are displaying the value for that column, then closing the td and tr that the control created. Then you are creating a new tr and td with a colspan equal to the number of columns and putting in the course values then letting the control close those trs and tds.
I strongly urge you to use a repeater or listview for this. It will make your life a lot easier.
Upvotes: 1