Re: get datagrid.datasource gives error

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



try casting

Not sure of the the VB code but in C#

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

"vips" <ypul@xxxxxxxxxxx> wrote in message
news:OZgY96xSFHA.3636@xxxxxxxxxxxxxxxxxxxxxxx
> 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
>
>
>
>


.


Quantcast