Solved

Bind Datagrid to session variables

Posted on 2004-10-13
7
663 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

790 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