473,387 Members | 1,844 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,387 software developers and data experts.

get datagrid.datasource gives error

Page_Load

datagrid1.datasource=dataset1

//I am filling the datagrid and it works fine when page is displayed

end

---------------

button 1_click

dim ds as dataset

ds=datagrid1.datasource

//gives error

end

when I try to get the datasource from a datagrid (i.e. a dataset) it gives
error

"Object reference not set to an instance of an object."

is it due to postback event the datagrid's datasource is not accessible ??

vips


Nov 19 '05 #1
6 1927
try casting

Not sure of the the VB code but in C#

DataSet ds = new DataSet();
ds = (dataset)datagrid1.datasource;

"vips" <yp**@hotmail.com> wrote in message
news:OZ**************@TK2MSFTNGP14.phx.gbl...
Page_Load

datagrid1.datasource=dataset1

//I am filling the datagrid and it works fine when page is displayed

end

---------------

button 1_click

dim ds as dataset

ds=datagrid1.datasource

//gives error

end

when I try to get the datasource from a datagrid (i.e. a dataset) it gives
error

"Object reference not set to an instance of an object."

is it due to postback event the datagrid's datasource is not accessible ??

vips

Nov 19 '05 #2
That's right. The datasource isn't maintained in viewstate as a raw
dataset..instead only the information necessary to the datagrid (rows,
columns, ...) are maintained. If you need the dataset again you'll need
to either recreate it or store it somewhere...

KArl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"vips" <yp**@hotmail.com> wrote in message
news:OZ**************@TK2MSFTNGP14.phx.gbl...
Page_Load

datagrid1.datasource=dataset1

//I am filling the datagrid and it works fine when page is displayed

end

---------------

button 1_click

dim ds as dataset

ds=datagrid1.datasource

//gives error

end

when I try to get the datasource from a datagrid (i.e. a dataset) it gives
error

"Object reference not set to an instance of an object."

is it due to postback event the datagrid's datasource is not accessible ??

vips

Nov 19 '05 #3
it'd be ctype(DataGrid1.DataSource, DataSet) but if that was the error I
wouldn't expect him to get a nullreference error...instead I'd expect him to
get an invalid cast...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Grant Merwitz" <gr***@workshare.com> wrote in message
news:uO**************@TK2MSFTNGP09.phx.gbl...
try casting

Not sure of the the VB code but in C#

DataSet ds = new DataSet();
ds = (dataset)datagrid1.datasource;

"vips" <yp**@hotmail.com> wrote in message
news:OZ**************@TK2MSFTNGP14.phx.gbl...
Page_Load

datagrid1.datasource=dataset1

//I am filling the datagrid and it works fine when page is displayed

end

---------------

button 1_click

dim ds as dataset

ds=datagrid1.datasource

//gives error

end

when I try to get the datasource from a datagrid (i.e. a dataset) it
gives
error

"Object reference not set to an instance of an object."

is it due to postback event the datagrid's datasource is not accessible
??

vips


Nov 19 '05 #4
I am getting datagrid.datasource as nothing !!

"Grant Merwitz" <gr***@workshare.com> wrote in message
news:uO**************@TK2MSFTNGP09.phx.gbl...
try casting

Not sure of the the VB code but in C#

DataSet ds = new DataSet();
ds = (dataset)datagrid1.datasource;

"vips" <yp**@hotmail.com> wrote in message
news:OZ**************@TK2MSFTNGP14.phx.gbl...
Page_Load

datagrid1.datasource=dataset1

//I am filling the datagrid and it works fine when page is displayed

end

---------------

button 1_click

dim ds as dataset

ds=datagrid1.datasource

//gives error

end

when I try to get the datasource from a datagrid (i.e. a dataset) it gives error

"Object reference not set to an instance of an object."

is it due to postback event the datagrid's datasource is not accessible ??
vips


Nov 19 '05 #5

u mean I need to keep the dataset it in viewstate ??
but the framework itself keeps it in viewstate ...cant i access it some how
??


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:u1****************@TK2MSFTNGP14.phx.gbl...
That's right. The datasource isn't maintained in viewstate as a raw
dataset..instead only the information necessary to the datagrid (rows,
columns, ...) are maintained. If you need the dataset again you'll need
to either recreate it or store it somewhere...

KArl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"vips" <yp**@hotmail.com> wrote in message
news:OZ**************@TK2MSFTNGP14.phx.gbl...
Page_Load

datagrid1.datasource=dataset1

//I am filling the datagrid and it works fine when page is displayed

end

---------------

button 1_click

dim ds as dataset

ds=datagrid1.datasource

//gives error

end

when I try to get the datasource from a datagrid (i.e. a dataset) it gives error

"Object reference not set to an instance of an object."

is it due to postback event the datagrid's datasource is not accessible ??
vips


Nov 19 '05 #6
I mean, you can keep it wherever you want...viewstate, session,
cache..whatever appropriate for your situation (don't know enough to tell
you).

The framework doesn't keep the dataset in the viewstate. It keeps the
controls which make up the datagrid (which were build using the dataset) but
not the dataset itself...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"vips" <yp**@hotmail.com> wrote in message
news:OG**************@TK2MSFTNGP09.phx.gbl...

u mean I need to keep the dataset it in viewstate ??
but the framework itself keeps it in viewstate ...cant i access it some
how
??


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:u1****************@TK2MSFTNGP14.phx.gbl...
That's right. The datasource isn't maintained in viewstate as a raw
dataset..instead only the information necessary to the datagrid (rows,
columns, ...) are maintained. If you need the dataset again you'll
need
to either recreate it or store it somewhere...

KArl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"vips" <yp**@hotmail.com> wrote in message
news:OZ**************@TK2MSFTNGP14.phx.gbl...
> Page_Load
>
> datagrid1.datasource=dataset1
>
> //I am filling the datagrid and it works fine when page is displayed
>
> end
>
> ---------------
>
> button 1_click
>
> dim ds as dataset
>
> ds=datagrid1.datasource
>
> //gives error
>
> end
>
>
>
> when I try to get the datasource from a datagrid (i.e. a dataset) it gives > error
>
> "Object reference not set to an instance of an object."
>
> is it due to postback event the datagrid's datasource is not accessible ?? >
>
>
> vips
>
>
>
>



Nov 19 '05 #7

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

Similar topics

13
by: DraguVaso | last post by:
Hi, I need a function that gives me the number of Columns shown in a DataGrid. So I don't need to know the number of columns shown in tha DataSource, because this number can be completely...
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
2
by: Brett | last post by:
I have the following code in VS Studio .NET 2005 beta: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.DataAdapter1.Fill(DataSet1) ...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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...

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.