Reputation: 823
Is it possible to move a column to the next row in a gridview somehow?
Like this:
This really is the best way to explain what i'm trying to do.
here's some code for you nice fellows.
ASP.NET
<asp:GridView
runat="server"
ID="Notifications"
CssClass="Notifications"
PageSize="30"
AllowPaging="true"
AutoGenerateColumns="false"
ShowHeader="false"
OnRowCreated="Notifications_RowCreated">
<RowStyle CssClass="TableRow" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="IMG_Seen" runat="server" AlternateText="Error" ImageUrl='<%# Eval("cSeen") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="IMG_Status" runat="server" AlternateText="Error" ImageUrl='<%# Eval("cStatus") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="L_Title" runat="server" Text='<%# Eval("cTitle") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="L_Date" runat="server" Text='<%# Eval("cDate") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="L_Description" runat="server" Text='<%# Eval("cDescription") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lLB_inkTo" runat="server" PostBackUrl='<%# Eval("clinkto") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
C# -Gridview bind method
void Init_Notifications(XDocument xDoc)
{
GridView GV = Notifications;
var Root = from p in xDoc.Descendants("User") select p;
var getNotify = from n in Root.Descendants("Notifications") select n;
foreach (XElement xe in getNotify.Nodes())
{
NotifList.Add(new Notification(
xe.Attribute("ID").Value,
xe.Attribute("Status").Value,
xe.Attribute("Title").Value,
xe.Attribute("Seen").Value,
xe.Attribute("linkTo").Value,
xe.Element("Description").Value
)
);
}
DataTable DT = new DataTable();
DT.Columns.Add("cDate", typeof(System.String));
DT.Columns.Add("cStatus", typeof(System.String));
DT.Columns.Add("cTitle", typeof(System.String));
DT.Columns.Add("cSeen", typeof(System.String));
DT.Columns.Add("cDescription", typeof(System.String));
DT.Columns.Add("clinkTo", typeof(System.String));
foreach (Notification n in NotifList)
{
object[] RowContent =
{
n.pDate,
n.pStatus,
n.pTitle,
n.pSeen,
n.pDescription,
n.pLinkTo
};
DT.Rows.Add(RowContent);
}
Notifications.DataSource = DT;
Notifications.DataBind();
}
Im basically trying to somehow convert / move this into a new row via codebehind or aspx code.
I couldn't get this to look great using CSS as well
Upvotes: 1
Views: 2828
Reputation: 13038
Yes that is certainly possible =) You can achieve this by rendering the gridview column as a new table row on your aspx page. Just add a template field in your gridview & include tr, td tags like this
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%">
<!-- Insert your label, boundfield controls etc -->
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
Upvotes: 1