Article: Rotate ASP.Net GridView - Convert GridView Columns to Rows and Rows to Columns
I am trying it this way i wanted but when it comes out it loads only one record
please help thanks
If Not IsPostBack Then
Using Con As New SqlConnection(constr)
Con.Open()
Using Com As New SqlCommand("Select * from Timeavailable", Con)
Using RDR = Com.ExecuteReader()
If RDR.HasRows Then
Do While RDR.Read
streamr = RDR.Item("slottitle").ToString()
Numbers = RDR.Item("DayTimeSlotID").ToString()
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(2) {New DataColumn("Item"), New DataColumn("Quantity"), New DataColumn("Price")})
dt.Rows.Add(streamr, Numbers, 500)
dt.Rows.Add(streamr, 0, 2000)
ViewState("dt") = dt
BindGrid(dt, False)
Loop
End If
End Using
End Using
End Using
End If
End Sub
Private Sub BindGrid(dt As DataTable, rotate As Boolean)
TimeTableGrd.ShowHeader = Not rotate
TimeTableGrd.DataSource = dt
TimeTableGrd.DataBind()
If rotate Then
For Each row As GridViewRow In TimeTableGrd.Rows
row.Cells(0).CssClass = "header"
Next
End If
End Sub
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="CreateTables.aspx.vb" Inherits="TMIS.CreateTables" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.auto-style2 {
width: 100%;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<table class="auto-style2">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<asp:GridView ID="TimeTableGrd" runat="server">
</asp:GridView>
</td>
</tr>
</table>
</asp:Content>