Solved

Bind Datagrid to session variables

Posted on 2004-10-13
7
655 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now