473,721 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get datagrid.dataso urce gives error

Page_Load

datagrid1.datas ource=dataset1

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

end

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

button 1_click

dim ds as dataset

ds=datagrid1.da tasource

//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 1963
try casting

Not sure of the the VB code but in C#

DataSet ds = new DataSet();
ds = (dataset)datagr id1.datasource;

"vips" <yp**@hotmail.c om> wrote in message
news:OZ******** ******@TK2MSFTN GP14.phx.gbl...
Page_Load

datagrid1.datas ource=dataset1

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

end

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

button 1_click

dim ds as dataset

ds=datagrid1.da tasource

//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..instea d 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.c om> wrote in message
news:OZ******** ******@TK2MSFTN GP14.phx.gbl...
Page_Load

datagrid1.datas ource=dataset1

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

end

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

button 1_click

dim ds as dataset

ds=datagrid1.da tasource

//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***@workshar e.com> wrote in message
news:uO******** ******@TK2MSFTN GP09.phx.gbl...
try casting

Not sure of the the VB code but in C#

DataSet ds = new DataSet();
ds = (dataset)datagr id1.datasource;

"vips" <yp**@hotmail.c om> wrote in message
news:OZ******** ******@TK2MSFTN GP14.phx.gbl...
Page_Load

datagrid1.datas ource=dataset1

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

end

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

button 1_click

dim ds as dataset

ds=datagrid1.da tasource

//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.dataso urce as nothing !!

"Grant Merwitz" <gr***@workshar e.com> wrote in message
news:uO******** ******@TK2MSFTN GP09.phx.gbl...
try casting

Not sure of the the VB code but in C#

DataSet ds = new DataSet();
ds = (dataset)datagr id1.datasource;

"vips" <yp**@hotmail.c om> wrote in message
news:OZ******** ******@TK2MSFTN GP14.phx.gbl...
Page_Load

datagrid1.datas ource=dataset1

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

end

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

button 1_click

dim ds as dataset

ds=datagrid1.da tasource

//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******** ********@TK2MSF TNGP14.phx.gbl. ..
That's right. The datasource isn't maintained in viewstate as a raw
dataset..instea d 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.c om> wrote in message
news:OZ******** ******@TK2MSFTN GP14.phx.gbl...
Page_Load

datagrid1.datas ource=dataset1

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

end

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

button 1_click

dim ds as dataset

ds=datagrid1.da tasource

//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...viewstat e, 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.c om> wrote in message
news:OG******** ******@TK2MSFTN GP09.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******** ********@TK2MSF TNGP14.phx.gbl. ..
That's right. The datasource isn't maintained in viewstate as a raw
dataset..instea d 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.c om> wrote in message
news:OZ******** ******@TK2MSFTN GP14.phx.gbl...
> Page_Load
>
> datagrid1.datas ource=dataset1
>
> //I am filling the datagrid and it works fine when page is displayed
>
> end
>
> ---------------
>
> button 1_click
>
> dim ds as dataset
>
> ds=datagrid1.da tasource
>
> //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
4624
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 something else than the number of columns defined in the currently active TableStyle! I currently use DataGrid.TableStyles(0).GridColumnStyles.Count, but i know this won't work when using more than one TableStyle, or having a TableStyle with another...
2
4328
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 how to use this code? please help! http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20862953.html
2
1631
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) End Sub Where a database connection has been made during design time and I can preview data. The above line gives a "specified method is not supported
0
2087
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 help........pls urgent ========================================================= <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm3.aspx.vb" Inherits="TestDatagrids.WebForm3"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">...
0
8840
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
8730
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,...
1
9131
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,...
0
9064
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8007
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4484
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3189
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
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.