Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrid/dataset state

Status
Not open for further replies.

gagz

Programmer
Nov 21, 2002
333
US
hi-

I'v got a page where a user enters some data in text boxes, etc, the clicks add and should add to a dynamically created table below. I figured that by having the table be a datagrid control and using a dataset in code-behind, I'd have this covered. However I'm not sure how to access the stuff. I figured that if the page hadn't posted back (ie the when its initially loaded), i'd create a blank dataset, bind it to the datagrid, and go from there. but when I went to code it:
Code:
        If Not IsPostBack Then
            Dim ds As New DataSet("MeetingDetails")

            Dim dTable As New DataTable("Details")
            dTable.Columns.Add("Date", System.Type.GetType("System.String"))
            dTable.Columns.Add("Start", System.Type.GetType("System.String"))
            dTable.Columns.Add("End", System.Type.GetType("System.String"))
            dTable.Columns.Add("NumAttendees", System.Type.GetType("System.String"))
            dTable.Columns.Add("Type", System.Type.GetType("System.String"))
            dTable.Columns.Add("Setup", System.Type.GetType("System.String"))
            dTable.Columns.Add("AV", System.Type.GetType("System.String"))
            dTable.Columns.Add("NumDays", System.Type.GetType("System.String"))

            ds.Tables.Add(dTable)

        End If

        Dim dr As DataRow = dTable.NewRow()
        dr(0) = "test"
        dr(1) = "test"
        dr(2) = "test"
        dr(3) = "test"
        dr(4) = "test"
        dr(5) = "test"
        dr(6) = "test"
        dr(7) = "test"
        dTable.Rows.Add(dr)

        MeetingDetails.DataSource = ds
        MeetingDetails.DataBind()
... it doesn't let me at the row and databind out of the if statement... both the dTable and ds are "undeclared". I didn't realize this happened inside if statements. what my goal is, is when the add button is clicked, I update the dataset, and rebind it... but there must be some intricacies that I'm unaware of.

Can someone shed some light?

Thanks,
Marc
 
Just looking over this quick like you should just be able to move your dim statment and it'll work. The problem is that only if your "IF" statment is true will the variable ds be created. So just move that dim somwhere above the if and you'll be fine. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
ok i'll give it a shot... but what I don't want to happen is that everytime the page posts back, a new ds is created, over writing the other... that or i have to figure out how to repopulate it...
 
The other dataset doesn't ever exist on a post back. The data itself may be displaying on the page in static form on a datagrid or some other control but the dataset variable is gone unless you do something specifically to keep it. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
ok i bet you can guess my next question... I'm either brain farting or its harder than i thought... whats the best way to "keep" it. seems like this would be a common thing done...
 
First I'll ask why you want to keep it? Like I said your data is most likely persisted in a datagrid or somehow on the page. Even though that data isn't in a dataset, it is still on the page.

If you do insist on persisting your dataset itself then there are the usual routes of session variables or you could persist it through the view state. Neither of which are desirable. The session option means that once your site becomes popular your going to need and ginormas amount of memory or you'll notice some serious performance issues with your site. The view state sucks because your then sending the same data down to the client twice once persisted in your page and once in the viewstate item that you create. If your dataset is rather large, which they definitely can be, then your user is going to be downloading all of that data each post back.

Due to alot of the tweaks that have been put in ADO.NET if your using a SQL server you could just request that data from the server again. It's kind of one of those choose your poison situations.

My advice would be not to persist the dataset but to grab it from SQL when you need it. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
well maybe i should explain more about what this is actually needed for...
There are a few items, dates, time, setups, etc, that are text boxes and drop down lists relating to buisness meetings. there appear in one row on a request for proposal page, and the user had and "add" button to add the data to what i hope will become a dynamic table on the page, so he/she can see the list grow as they add more line items... sooo... once they have "added" the line item, it postsback to the server, so are you saying that I don't need to worry about the dataset, that I can just add to the grid and it won't lose whats there? I figured it would. I thought it would be alot of over head to add to a sql table, since there is no real way to identify who is filling this out (other than something like a sessionid). I was just hoping there was a well known way to do this... like i said before, seems like something a lot of people woudl want to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top