Solved

Bind Datagrid to session variables

Posted on 2004-10-13
7
652 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
Comment Utility
>>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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 15

Expert Comment

by:praneetha
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Dim dt As DataTable
dt = CType(Session("Temp"),DataTable)

guess like that
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

13 Experts available now in Live!

Get 1:1 Help Now