[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Bind Datagrid to session variables

Posted on 2004-10-13
7
Medium Priority
?
670 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

650 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