473,657 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView DataSource Is Nothing

I am trying to cast my Gridview in my Code behide as a Dataset so I can
manipulate the data. Here is the code snippet:

Dim FilteredDataSet As New System.Data.Dat aSet

Dim gv As New GridView
gv = CType(tbl_Repor tData.FindContr ol("GridView_1" ), GridView)
gv.GridLines = GridLines.Both
gv.DataBind()
FilteredDataSet = DirectCast(gv.D ataSource, System.Data.Dat aSet)
Now the issue I'm running into is the gv.DataSource is Nothing. My
GridView_1 control which I assign my gv to is bound to a <asp:SqlDataSou rce
ID="SqlDataSour ce1on the HTML side and loads GridView_1 fine. Even if I
assign the gv.DataSource as "gv.DataSou rce =
CType(tbl_Repor tData.FindContr ol("GridView_1" ), GridView).DataS ource", the
DataSource still shows nothing. When I check
CType(tbl_Repor tData.FindContr ol("GridView_1" ), GridView).DataS ourceID the is
shows SqlDataSource1.

Can anyone tell why my GridView_1 gets populated just fine but the
DataSource shows NOTHING, which is preventing me from creating a DataSet from
my GridView? If my syntax is wrong can you show me how to fix it?

Thanks,
Jul 31 '08 #1
7 4913
Hi,

First assign a dataset as a data source of the grid..
then try to cast...

Regards

Munna
Jul 31 '08 #2
Dim gv As New GridView

I believe this should better be

Dim gv As GridView

gv = CType(tbl_Repor tData.FindContr ol("GridView_1" ),
Can anyone tell why my GridView_1 gets populated just fine but the
DataSource shows NOTHING, which is preventing me from creating a DataSet
from my GridView?
Possibly because you're trying to access the DataSource property before it
has been set. Is it still nothing in say Page_PreRender or
GridView_1_OnDa taBound?

--
Ben | bschwehn.de
Jul 31 '08 #3

Yes, the PreRender shows it as NOTHING. I Changed the declaration to Dim gv
as GridView as you suggested but it didn't work.

"Ben Schwehn" wrote:
Dim gv As New GridView

I believe this should better be

Dim gv As GridView

gv = CType(tbl_Repor tData.FindContr ol("GridView_1" ),
Can anyone tell why my GridView_1 gets populated just fine but the
DataSource shows NOTHING, which is preventing me from creating a DataSet
from my GridView?

Possibly because you're trying to access the DataSource property before it
has been set. Is it still nothing in say Page_PreRender or
GridView_1_OnDa taBound?

--
Ben | bschwehn.de
Jul 31 '08 #4

The problem is, I can't assign the DataSet to the GridView_1 DataSource
because CType(tbl_Repor tData.FindContr ol("GridView_1" ), GridView).DataS ource
also returns NOTHING. GridView_1 gets rendered because it's DataSourceID is
assigned to <asp:SqlDataSou rce ID="SqlDataSour ce1>.

"Munna" wrote:
Hi,

First assign a dataset as a data source of the grid..
then try to cast...

Regards

Munna
Jul 31 '08 #5
I'm not 100% certain of this, but is it possible that when you set the
DataSourceID on your Gridview to a <asp:SqlDataSou rceor
<asp:ObjectData Sourcethat the your DataSource of your Gridview will return
NOTHING?

"SAL" wrote:
I am trying to cast my Gridview in my Code behide as a Dataset so I can
manipulate the data. Here is the code snippet:

Dim FilteredDataSet As New System.Data.Dat aSet

Dim gv As New GridView
gv = CType(tbl_Repor tData.FindContr ol("GridView_1" ), GridView)
gv.GridLines = GridLines.Both
gv.DataBind()
FilteredDataSet = DirectCast(gv.D ataSource, System.Data.Dat aSet)
Now the issue I'm running into is the gv.DataSource is Nothing. My
GridView_1 control which I assign my gv to is bound to a <asp:SqlDataSou rce
ID="SqlDataSour ce1on the HTML side and loads GridView_1 fine. Even if I
assign the gv.DataSource as "gv.DataSou rce =
CType(tbl_Repor tData.FindContr ol("GridView_1" ), GridView).DataS ource", the
DataSource still shows nothing. When I check
CType(tbl_Repor tData.FindContr ol("GridView_1" ), GridView).DataS ourceID the is
shows SqlDataSource1.

Can anyone tell why my GridView_1 gets populated just fine but the
DataSource shows NOTHING, which is preventing me from creating a DataSet from
my GridView? If my syntax is wrong can you show me how to fix it?

Thanks,
Jul 31 '08 #6
On Thu, 31 Jul 2008 11:11:01 -0700, SAL wrote:
Yes, the PreRender shows it as NOTHING.
Right, sorry.
When you're using a SqlDataSource and bind it via the DataSourceId, the
DataSource property just is not set. Also there isn't even a DataSet
involved, that you could get.

But you can get a *DataView* by calling the Select method on your
SqlDataSource like

TheSqlDataSourc e.Select(DataSo urceSelectArgum ents.Empty);

As an alternative you could always just use old style databinding w/o
DataSourceId.

I Changed the declaration to
Dim gv as GridView as you suggested but it didn't work.
That was an unrelated problem, your code just created a new GridView
object for no good reason.
Jul 31 '08 #7

Thanks for the info Ben it makes sense now. You are right, having "As New
GridView" was overkill but I had it there because I thought maybe I was
missing something which it's clear that I wasn't.

What did you mean by "As an alternative you could always just use old style
databinding w/o DataSourceId"? I am assuming you mean to set the DataSource
of the GridView in the Code behind prior to Rendering the Gridview.
"Ben Schwehn" wrote:
On Thu, 31 Jul 2008 11:11:01 -0700, SAL wrote:
Yes, the PreRender shows it as NOTHING.

Right, sorry.
When you're using a SqlDataSource and bind it via the DataSourceId, the
DataSource property just is not set. Also there isn't even a DataSet
involved, that you could get.

But you can get a *DataView* by calling the Select method on your
SqlDataSource like

TheSqlDataSourc e.Select(DataSo urceSelectArgum ents.Empty);

As an alternative you could always just use old style databinding w/o
DataSourceId.

I Changed the declaration to
Dim gv as GridView as you suggested but it didn't work.

That was an unrelated problem, your code just created a new GridView
object for no good reason.
Jul 31 '08 #8

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

Similar topics

4
13484
by: Jim Katz | last post by:
I have an application that updates a strongly typed data set at run time. I'd like to dynamically create a table that connects to a run time data table. For displaying the data, this works well. I just set the GridView.DataSource once, and call DataBind(); I'd like to drive the application from the GridView control, by including command buttons that allow editing of the data. Starting out simple, I have a DataTable with a boolean...
5
4119
by: Diane Truyens | last post by:
Hi, I have a form with textboxes, a search button and a gridview. The textboxes are filled with default values so that the gridview should return all rows but not before the user has had the chance to change some of the textboxes and has clicked the search button. How can I avoid the gridview displaying all rows before the search button was clicked? Any Ideas? Thanks Diane
0
1162
by: bhawin13 | last post by:
Hello, I am not able to see any records in GridView2. GridView2 is not shown. I tried to print record count of datatable and it shows there is records but nothing is shown in gridview2. First I try to list products table in gridview1 I have added one column which shows select with hyperlink When I click on select It adds that row from Products table to datatable dt for gridview1 GridView1_SelectedIndexChanged event is written.
1
3522
by: jmdolinger | last post by:
Hi all, I'm a newbie to Atlas (and recently ASP.NET) after coming from a long Java background, also have done quite a bit with an Ajax.NET/ASP.NET 1.1 project, but it was basically all javascript, nothing really having to do with ASP.NET... I'm attempting to put together an application that consists of several GridView controls each bound to some xml data. Each table exists in its own update panel. The two effects I'm going for are:
2
6928
by: jobs | last post by:
I have a gridview that is refreshes when a dropdown is selected outside of it. Sorting is enabled on the gridview but not working. I read that I should set EnableSortingandPagingCallback to true to fix the error: The GridView 'GridView1' fired event Sorting which wasn't handled However, I am now getting:
3
7233
by: jobs | last post by:
I've got a gridview that does not have a datasourceid assigned in the markup. I'd like to switch between two datasources in the codebehind. when I do switch, I first reset the the gridviewx.datasource = nothing and gridviewx.datasourceid = nothing before setting it to gridviewx.datasource = newdatasoruceid and then rebinding. All appears to work well until I try to excute a delete command that
0
1016
by: jobs | last post by:
Is there a correct way to change the datasourceId of a gridview in codebehind so that things like sorting, paging and deleting actually work? Or will have have to have one one to one relationship between datasources and gridviews? when I switch datasources - deletes don't happen and I get erros like this when I try to page or sort:
7
17312
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi all! I have a gridview inside a datagrid (nested) for which (gridview) the rowcommand is not raised in order to delete a row from the grid! I also tried OnRowCommand="method", didn't work either! Does anyone know how can I make this work? Thanks in advance!
4
9781
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This sounds easy but the next requirement is that the GridView is editable. So I have included the SelectCommand and the UpdateCommand on the SqlDataSource to allow the GridView to be editable. I have now been able to get the GridView to display data...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8508
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
7341
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
5633
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
4164
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...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2733
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
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.