473,781 Members | 2,491 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pulling the Dataset from a Datagrid

I was just wondering if it's possible to cast a datagrid DataSource as a
DataSet?

I've stepped through my code when the grid is first being bound and the
DataSource shows up as a DataSet for the datagrid. Then, when I handle on
OnClick event for an image button and the page posts back, I look at the
DataSource for the grid and it says it's null. Is there any way of getting
the grid's current datasource after it loads?

I've tried this exact snipit of code:
DataSet ds = (DataSet)dgResu lts.DataSource; ....but this is where it says
the DataSource is null.

I want to be able to pull the datasource into a dataset, add a new row to
the dataset and rebind the datagrid showing a new blank row in the grid.

Any help would be appreciated.
--
Thanks in advance,

John Scott.
Jul 21 '05 #1
1 1489
"John Scott" wrote:
I was just wondering if it's possible to cast a datagrid DataSource as a
DataSet?

I've stepped through my code when the grid is first being bound and the
DataSource shows up as a DataSet for the datagrid. Then, when I handle on
OnClick event for an image button and the page posts back, I look at the
DataSource for the grid and it says it's null. Is there any way of getting
the grid's current datasource after it loads?

I've tried this exact snipit of code:
DataSet ds = (DataSet)dgResu lts.DataSource; ....but this is where it says
the DataSource is null.

I want to be able to pull the datasource into a dataset, add a new row to
the dataset and rebind the datagrid showing a new blank row in the grid.


what happens is that the dataset is "forgotten" on each postback.
The only reason why you see data at all in the grid is because of the
viewstate preserving it. The viewstate only preserves the data though, not
where its coming from. so you go from having the data in a dataset (relations
etc) to having just the raw data in a table.

The "cure" would be to store the dataset on the session by using

Session["somekey"] = myDataSet;

for example at the end of the pageload ( if(!IsPostBack) )

then retrieving it when you need it

(if( myDataSet == null ) { myDataSet = Session["somekey"] as DataSet; }

after doing this you are left with your original dataset. modify it and do a
databind again and you should be set

mvh
Andreas
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1634
by: PuckInLA | last post by:
I have a question. I have some data that I am pulling into a dataset that needs to have each row of data emailed out. I got the email funciton working great but its extracting that data that is becoming the problem. I assume it would be in a loop, and to do that I am guessing something like this: for each item in dataset extact row email rowinfo for next
0
1065
by: ar | last post by:
Hi, I have a page where I have a dataset with a single table (table1) with a single column (col1). I am very simply trying to add items to the dataset one at a time, and rebind the dataset to a datagrid after adding each item. I guess my question is ...does a dataset/datatable not hold a value after a postback? Or maybe my code is just wrong....but my datagrid doesn't add additional items like I want it to when I click Button1. My...
0
1978
by: Frosty | last post by:
Hi I am using the VS xsd designer to create a strongly typed dataset. The dataset is apparently successfully created, with no warnings or errors given. Is it not then to be expected that this dataset then should reflect all the details put into the xsd? Somewhere down the line there is not a 1:1 relationship. Be it that .NET is so tightly coupled to xsd, xml and dataset I would have expected any discrepancies to have been well documented and...
3
2548
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called "Resource" with the following structure : Resource{,en,fr,es} Yes.. these are the only languages supported actually. A couple of rows in that table would look like this :
4
2308
by: washoetech | last post by:
Hello, I am working on a project where I need to be able to grab the data from an Excel spreadsheet and create a new table in my database based on the columns in the spreadsheet. After the table is created then I need to fill the table with the data from that spreadsheet. I am using ASP.NET 2.0 and SQL 2000 for my database. What would be the best way to do this? Should I go Excel to XML or Excel to a Dataset?
3
2521
by: Datatable Dataset Datagrid help | last post by:
Hi I am somewhat confused, I am new at VB.net I use XML data, I have a datagrid, I created a datatable so that I can create a custom format like true is this graphic false is this graphic and others. One of the custom format is as follows: dsmessages_dt.Columns.Add("Image", GetType(Image)) I had a problem of when I used a checkbox in the grid that was bound to the datatable that it would not update my dataset. So I created another...
17
2771
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only allow user to filter the first time, when they tried the second time, the speficied cast error message will prompt one.... I create a mydataset1 first, and the mydataset1 data source was getting from DataGrid.DataSource.
1
244
by: John Scott | last post by:
I was just wondering if it's possible to cast a datagrid DataSource as a DataSet? I've stepped through my code when the grid is first being bound and the DataSource shows up as a DataSet for the datagrid. Then, when I handle on OnClick event for an image button and the page posts back, I look at the DataSource for the grid and it says it's null. Is there any way of getting the grid's current datasource after it loads? I've tried...
0
1863
by: Jerms | last post by:
Hello all, I've been using this site quite a bit since starting my project and have found it very helpful. I have run into a roadblock though that I cant seem to scrounge up a solution to. I have this dataset created (REACHpointsdataset) with a few tables in it (points, users, items, etc.), I also add another table to this database though code which I pull from a webservice. Two of the tables are of interest to me right now are empl (from...
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10143
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10076
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.