By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,695 Members | 1,356 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,695 IT Pros & Developers. It's quick & easy.

get datagrid.datasource gives error

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.