473,382 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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)dgResults.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 1465
"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)dgResults.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
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...
0
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...
0
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...
3
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...
4
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...
3
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...
17
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...
1
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...
0
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.