VB.NET - To display gridview in vertical direction

Asked By abinav shankar on 05-Dec-11 12:09 AM

I have some data in datatable and i am binding it to the grid view and it looks like this

header1 header2
value1    value2

but i want to display in this way

header1  value1
header2  value2

I am storing the data in datable like


Jitendra Faye replied to abinav shankar on 05-Dec-11 12:12 AM

You can assign this as your HeaderStyle


.verticaltext {

writing-mode: tb-rl;

filter: flipv fliph;




Riley K replied to abinav shankar on 05-Dec-11 12:14 AM

There's separate control in asp.net for this purpose.... detailsview

Sakshi a replied to abinav shankar on 05-Dec-11 12:18 AM

this is a working sample for vertical rows, but in c#, you can use any code conversion site to covert to vb.net.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FlipGridView.aspx.cs" Inherits="XmlPostData" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">  <title>Untitled Page</title></head><body>  <form id="form1" runat="server">    <div>      <asp:GridView ID="GridView1" runat="server" ShowHeader="false" AllowSorting="true">      </asp:GridView>    </div>  </form></body></html>
using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Net;using System.Text;using System.IO;public partial class FlipGridView:System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {       GridView1.DataSource = FlipDataSet(c());      GridView1.DataBind();    }    public DataSet c()    {      DataSet ds = new DataSet();      DataTable dt = new DataTable("Company");      DataRow dr;      dt.Columns.Add(new DataColumn("accountNo", typeof(Int32)));      dt.Columns.Add(new DataColumn("CompanyName", typeof(string)));      dt.Columns.Add(new DataColumn("Address", typeof(string)));      for (int i = 0; i <= 10; i++)      {        dr = dt.NewRow();        dr[0] = i;        dr[1] = "Company" + i + Environment.NewLine + "Title" + i;        dr[2] = "Address" + i + Environment.NewLine + "Title" + i;        dt.Rows.Add(dr);      }      ds.Tables.Add(dt);      return ds;    }    public DataSet FlipDataSet(DataSet my_DataSet)    {      DataSet ds = new DataSet();      foreach (DataTable dt in my_DataSet.Tables)      {        DataTable table = new DataTable();        for (int i = 0; i <= dt.Rows.Count; i++)        {          table.Columns.Add(Convert.ToString(i));        }        DataRow r = null;        for (int k = 0; k < dt.Columns.Count; k++)        {          r = table.NewRow();          r[0] = dt.Columns[k].ToString();          for (int j = 1; j <= dt.Rows.Count; j++)            r[j] = dt.Rows[j - 1][k];          table.Rows.Add(r);        }        ds.Tables.Add(table);      }      return ds;    }}
Chintan Vaghela replied to abinav shankar on 05-Dec-11 12:56 AM
Use Repeater control instead of GridView
Anoop S replied to abinav shankar on 05-Dec-11 01:57 AM
You can flip all the entries inside each table of the dataset, Here is the code for FlipDataSet method, is in the code behind file for me. In method FlipDataSet, I am doing flipping of dataset and in BindData, I am binding the first table of it to the DataGrid. This is all:

private void BindData()
    DataSet ds = this.GetDetail(); // Some DataSet

    DataSet new_ds = FlipDataSet(ds); // Flip the DataSet

    DataView my_DataView = new_ds.Tables[0].DefaultView;
    this.my_DataGrid.DataSource = my_DataView;

public DataSet FlipDataSet(DataSet my_DataSet)
    DataSet ds = new DataSet();
    foreach(DataTable dt in my_DataSet.Tables)
      DataTable table = new DataTable();
      for(int i=0; i<=dt.Rows.Count; i++)
      DataRow r;
      for(int k=0; k<dt.Columns.Count; k++)
        r = table.NewRow();
        r[0] = dt.Columns[k].ToString();
        for(int j=1; j<=dt.Rows.Count; j++)
          r[j] = dt.Rows[j-1][k];
return ds;

Old DataSet

Column1 Column2 Column3
Neeraj Jain Carios
Tashan Yen Agknow
Andrew Ferriere Feedback

Flipped DataSet

0 1 2 3
Column1 Neeraj Tashan Andrew
Column2 Jain Yen Agknow
Column3 Carios Agknow Feedback