Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make days vertical and grid view editable using asp.net vb

Status
Not open for further replies.

Makumbi256

Programmer
Mar 1, 2022
3
UG
Please help how can i display make the days to appear vertical and also make the grid view editable using asp.net thanks in advance.
Note : i would like the days to be vertical and not duplicated
i have attached a sample of the expected output

Code:
<%@ 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>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td colspan="2">
                <asp:GridView ID="TimeTableGrd" runat="server" Width="413px">
                </asp:GridView>
            </td>
        </tr>
    </table>
</asp:Content>

Code:
Imports System.Data.SqlClient

Public Class CreateTables
    Inherits System.Web.UI.Page
    Dim streamr, Numbers As String
    Dim constr As String = ConfigurationManager.ConnectionStrings("TMISConnectionString").ConnectionString
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        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 DataTable = Me.GetData()

                                ViewState("dt") = dt
                                BindGrid(dt, True)


                                Dim dt2 As New DataTable()
                                For i As Integer = 0 To dt.Rows.Count
                                    dt2.Columns.Add()
                                Next
                                For i As Integer = 0 To dt.Columns.Count - 1
                                    dt2.Rows.Add()
                                    dt2.Rows(i)(0) = dt.Columns(i).ColumnName
                                Next
                                For i As Integer = 0 To dt.Columns.Count - 1
                                    For j As Integer = 0 To dt.Rows.Count - 1
                                        dt2.Rows(i)(j + 1) = dt.Rows(j)(i)
                                    Next
                                Next
                                BindGrid(dt2, True)
                            Loop
                        End If
                    End Using
                End Using
            End Using


        End If
    End Sub

    Private Function GetData2015() As DataTable
        ' Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
        Using con As New SqlConnection(constr)
            Using cmd As New SqlCommand("SELECT Name AS DAYS FROM dbo.Timeavailable GROUP BY Name")
                Using sda As New SqlDataAdapter()
                    cmd.Connection = con
                    sda.SelectCommand = cmd
                    Using dt As New DataTable()
                        sda.Fill(dt)
                        Return dt
                    End Using
                End Using
            End Using
        End Using
    End Function
    Private Function GetData() As DataTable
        ' Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
        Using con As New SqlConnection(constr)
            Using cmd As New SqlCommand("SELECT SlotTitle, NAme as [Day]  FROM dbo.Timeavailable
GROUP BY SlotTitle,Name")
                Using sda As New SqlDataAdapter()
                    cmd.Connection = con
                    sda.SelectCommand = cmd
                    Using dt As New DataTable()
                        sda.Fill(dt)
                        Return dt
                    End Using
                End Using
            End Using
        End Using
    End Function


    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

the table below shows the Day and timeslot
[/CO
[TABLE]
[TR]
[TD][TABLE]
[TR]
[TD]SlotTitle[/TD]
[TD]DAY[/TD]
[/TR]
[TR]
[TD]08:00 AM-09:00 AM[/TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]09:00 AM-10:00 AM[/TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]10:00 AM-11:00 AM[/TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]11:00 AM-12:00 PM[/TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]12:00 PM-01:00 PM[/TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]01:00 PM-02:00 PM[/TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]02:00 PM-03:00 PM[/TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]03:00 PM-04:00 PM[/TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]08:00 AM-09:00 AM[/TD]
[TD]TUESDAY[/TD]
[/TR]
[TR]
[TD]09:00 AM-10:00 AM[/TD]
[TD]TUESDAY[/TD]
[/TR]
[TR]
[TD]10:00 AM-11:00 AM[/TD]
[TD]TUESDAY[/TD]
[/TR]
[TR]
[TD]11:00 AM-12:00 PM[/TD]
[TD]TUESDAY[/TD]
[/TR]
[TR]
[TD]12:00 PM-01:00 PM[/TD]
[TD]TUESDAY[/TD]
[/TR]
[TR]
[TD]01:00 PM-02:00 PM[/TD]
[TD]TUESDAY[/TD]
[/TR]
[TR]
[TD]02:00 PM-03:00 PM[/TD]
[TD]TUESDAY[/TD]
[/TR]
[TR]
[TD]03:00 PM-04:00 PM[/TD]
[TD]TUESDAY[/TD]
[/TR]
[TR]
[TD]08:00 AM-09:00 AM[/TD]
[TD]WEDNESDAY[/TD]
[/TR]
[TR]
[TD]09:00 AM-10:00 AM[/TD]
[TD]WEDNESDAY[/TD]
[/TR]
[TR]
[TD]10:00 AM-11:00 AM[/TD]
[TD]WEDNESDAY[/TD]
[/TR]
[TR]
[TD]11:00 AM-12:00 PM[/TD]
[TD]WEDNESDAY[/TD]
[/TR]
[TR]
[TD]12:00 PM-01:00 PM[/TD]
[TD]WEDNESDAY[/TD]
[/TR]
[TR]
[TD]01:00 PM-02:00 PM[/TD]
[TD]WEDNESDAY[/TD]
[/TR]
[TR]
[TD]02:00 PM-03:00 PM[/T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TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]11:00 AM-12:30 PM[/TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]12:30 PM-02:00 PM[/TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]02:00 PM-03:30 PM[/TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]03:30 PM-05:00 PM[/TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]09:30 AM-11:00 AM[/TD]
[TD]TUESDAY[/TD]
[/TR]
[TR]
[TD]11:00 AM-12:30 PM[/TD]
[TD]TUESDAY[/TD]
[/TR]
[TR]
[TD]12:30 PM-02:00 PM[/TD]
[TD]TUESDAY[/TD]
[/TR]
[TR]
[TD]02:00 PM-03:30 PM[/TD]
[TD]TUESDAY[/TD]
[/TR]
[TR]
[TD]03:30 PM-05:00 PM[/TD]
[TD]TUESDAY[/TD]
[/TR]
[TR]
[TD]09:30 AM-11:00 AM[/TD]
[TD]WEDNESDAY[/TD]
[/TR]
[TR]
[TD]11:00 AM-12:30 PM[/TD]
[TD]WEDNESDAY[/TD]
[/TR]
[TR]
[TD]12:30 PM-02:00 PM[/TD]
[TD]WEDNESDAY[/TD]
[/TR]
[TR]
[TD]02:00 PM-03:30 PM[/TD]
[TD]WEDNESDAY[/TD]
[/TR]
[TR]
[TD]03:30 PM-05:00 PM[/TD]
[TD]WEDNESDAY[/TD]
[/TR]
[TR]
[TD]09:30 AM-11:00 AM[/TD]
[TD]THURSDAY[/TD]
[/TR]
[TR]
[TD]11:00 AM-12:30 PM[/TD]
[TD]THURSDAY[/TD]
[/TR]
[TR]
[TD]12:30 PM-02:00 PM[/TD]
[TD]THURSDAY[/TD]
[/TR]
[TR]
[TD]02:00 PM-03:30 PM[/TD]
[TD]THURSDAY[/TD]
[/TR]
[TR]
[TD]03:30 PM-05:00 PM[/TD]
[TD]THURSDAY[/TD]
[/TR]
[TR]
[TD]09:30 AM-11:00 AM[/TD]
[TD]FRIDAY[/TD]
[/TR]
[TR]
[TD]11:00 AM-12:30 PM[/TD]
[TD]FRIDAY[/TD]
[/TR]
[TR]
[TD]12:30 PM-02:00 PM[/TD]
[TD]FRIDAY[/TD]
[/TR]
[TR]
[TD]02:00 PM-03:30 PM[/TD]
[TD]FRIDAY[/TD]
[/TR]
[TR]
[TD]03:30 PM-05:00 PM[/TD]
[TD]FRIDAY[/TD]
[/TR]
[TR]
[TD]08:00 AM-10:15 AM[/TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]10:15 AM-12:30 PM[/TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]12:30 PM-02:45 PM[/TD]
[TD]MONDAY[/TD]
[/TR]
[TR]
[TD]02:45 PM-05:00 PM[/TD]
[TD]MONDAY[/TD]
[/TR]
[/TABLE]
[/TD]
[/TR]
[/TABLE]
DE]

this attachment is what i want to be displayed with editable grid view
 

Attachments

  • LatestDisplay.png
    LatestDisplay.png
    11.1 KB · Views: 1
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top