Solved

Bind Datagrid to session variables

Posted on 2004-10-13
7
660 Views
Last Modified: 2008-02-01
VB.NET, SQL Server, Web Matrix.

I'm very new the ASP.NET so please be specific with answers if all possible.

I'm working on creating a scheduling system that stores all the users input in various sessions that will later be added to the database.  I'm now at a point where the user may enter in a date, start, and end time (startDate, startTime, endTime) for each meeting they would like to schedule.  I would like to give the user the option to add as many meetings as possible all on one page.  I thought about using a datagrid to do this.

What I would like to do is setup a datagrid that would ask a user his or her startDate, startTime, and endTime.  Give them the option to keep adding more (like an insert row thing).  When everything has been inserted they will submit it and go to the next page.  All the data entered will be stored in sessions which will later be stored to the database.  So, is it possible to bind a blank dataset to a session?

Thanks in advance.
0
Comment
Question by:rreister
  • 5
  • 2
7 Comments
 
LVL 15

Expert Comment

by:praneetha
ID: 12300418
>>the data entered will be stored in sessions which will later be stored to the database

how are u storing it in session...

0
 
LVL 15

Accepted Solution

by:
praneetha earned 125 total points
ID: 12300444
you can create datatable and everytime u have a new row..add it to the datatable and store the whole datatable to the session varianle..
like

Session["DataTable_Temp"]=dt;//

and while reading it from session use..

DataTable dt1=(DataTable)Session["DataTable_Temp"];//type cast it back to datatable...this is C#..

Thank you
good luck
0
 

Author Comment

by:rreister
ID: 12302050
Sounds like a good idea.  Can you help with the datatable?

Right now I have this:

sub Page_Load(sender as Object, e as EventArgs)
    IF NOT Page.IsPostBack THEN
    'Create the DataTable
    Dim dt as New DataTable

    'Create the columns
    Dim stDate as New DataColumn("startDate", GetType(String))
    Dim stTime as New DataColumn("startTime", GetType(String))
    Dim edTime as New DataColumn("endTime", GetType(String))

    'Add the columns to the DataTable's Columns collection
    dt.Columns.Add(stDate)
    dt.Columns.Add(stTime)
    dt.Columns.Add(edTime)

    'Bind the DataTable to the DataGrid
    showReservations.DataSource = dt
    showReservations.DataBind()

END IF
End Sub

Function updateTable()

    'Add some rows
    Dim dr as DataRow
    dr = dt.NewRow()
    dr("startDate") = startDate.SelectedDate.ToShortDateString()
    dr("startTime") = Request("startTime")
    dr("endTime") = Request("endTime")
    dt.Rows.Add(dr)

    'Bind the DataTable to the DataGrid
    showReservations.DataSource = dt
    showReservations.DataBind()
End Function

Sub Button2_Click(sender As Object, e As EventArgs)
updateTable()
End Sub


When Button2 is clicked then it should update the table and display the new results on the screen.  The error though lies in the Function.  dr = dt.NewRow().  dt is not defined.  How can I get the program to update the results of the datatable?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 15

Expert Comment

by:praneetha
ID: 12302112
IF NOT Page.IsPostBack THEN
    'Create the DataTable
    Dim dt as New DataTable

    'Create the columns
    Dim stDate as New DataColumn("startDate", GetType(String))
    Dim stTime as New DataColumn("startTime", GetType(String))
    Dim edTime as New DataColumn("endTime", GetType(String))

    'Add the columns to the DataTable's Columns collection
    dt.Columns.Add(stDate)
    dt.Columns.Add(stTime)
    dt.Columns.Add(edTime)

    'Bind the DataTable to the DataGrid
    showReservations.DataSource = dt
    showReservations.DataBind()
// add datatable to session variable
Session["Temp"]=dr;//this is C# please change it to vb.net

END IF

and

in finction

Function updateTable()

    'Add some rows
DataTable dt=(DataTable)Session["temp"];//C# again...sorry about that...
    Dim dr as DataRow
    dr = dt.NewRow()

0
 

Author Comment

by:rreister
ID: 12302218
Hmm.  No luck with that.  I changed the Session variable to VB.NET: Session("Temp") = dt

But I don't quite understand what DataTable dt=(DataTable)Session["temp"]; is supposed to do?
I converted it to: Dim dt as DataTable(Session.Contents("Temp"))  but, that gives an error: Array bounds cannot appear in type specifiers.

0
 
LVL 15

Expert Comment

by:praneetha
ID: 12302276
i guess you have to use CType in vb.net for typecasting

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctctype.asp

well

 DataTable dt=(DataTable)Session["temp"]; //is bringing back the table from session variable..

since when u click a button ...it goes to page_load...and u don't have dt available any more..so you have to store it in a session variable and use it in the button click...
0
 
LVL 15

Expert Comment

by:praneetha
ID: 12302291
Dim dt As DataTable
dt = CType(Session("Temp"),DataTable)

guess like that
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question