Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > GridView DataSource Is Nothing

Reply
Thread Tools

GridView DataSource Is Nothing

 
 
SAL
Guest
Posts: n/a
 
      07-31-2008
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.DataSet

Dim gv As New GridView
gv = CType(tbl_ReportData.FindControl("GridView_1"), GridView)
gv.GridLines = GridLines.Both
gv.DataBind()
FilteredDataSet = DirectCast(gv.DataSource, System.Data.DataSet)


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:SqlDataSource
ID="SqlDataSource1> on the HTML side and loads GridView_1 fine. Even if I
assign the gv.DataSource as "gv.DataSource =
CType(tbl_ReportData.FindControl("GridView_1"), GridView).DataSource", the
DataSource still shows nothing. When I check
CType(tbl_ReportData.FindControl("GridView_1"), GridView).DataSourceID 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,
 
Reply With Quote
 
 
 
 
Munna
Guest
Posts: n/a
 
      07-31-2008
Hi,

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

Regards

Munna
 
Reply With Quote
 
 
 
 
Ben Schwehn
Guest
Posts: n/a
 
      07-31-2008
> Dim gv As New GridView

I believe this should better be

Dim gv As GridView


> gv = CType(tbl_ReportData.FindControl("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_OnDataBound?



--
Ben | bschwehn.de
 
Reply With Quote
 
SAL
Guest
Posts: n/a
 
      07-31-2008

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_ReportData.FindControl("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_OnDataBound?
>
>
>
> --
> Ben | bschwehn.de
>

 
Reply With Quote
 
SAL
Guest
Posts: n/a
 
      07-31-2008

The problem is, I can't assign the DataSet to the GridView_1 DataSource
because CType(tbl_ReportData.FindControl("GridView_1"), GridView).DataSource
also returns NOTHING. GridView_1 gets rendered because it's DataSourceID is
assigned to <asp:SqlDataSource ID="SqlDataSource1>.

"Munna" wrote:

> Hi,
>
> First assign a dataset as a data source of the grid..
> then try to cast...
>
> Regards
>
> Munna
>

 
Reply With Quote
 
SAL
Guest
Posts: n/a
 
      07-31-2008
I'm not 100% certain of this, but is it possible that when you set the
DataSourceID on your Gridview to a <asp:SqlDataSource> or
<asp:ObjectDataSource> that 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.DataSet
>
> Dim gv As New GridView
> gv = CType(tbl_ReportData.FindControl("GridView_1"), GridView)
> gv.GridLines = GridLines.Both
> gv.DataBind()
> FilteredDataSet = DirectCast(gv.DataSource, System.Data.DataSet)
>
>
> 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:SqlDataSource
> ID="SqlDataSource1> on the HTML side and loads GridView_1 fine. Even if I
> assign the gv.DataSource as "gv.DataSource =
> CType(tbl_ReportData.FindControl("GridView_1"), GridView).DataSource", the
> DataSource still shows nothing. When I check
> CType(tbl_ReportData.FindControl("GridView_1"), GridView).DataSourceID 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,

 
Reply With Quote
 
Ben Schwehn
Guest
Posts: n/a
 
      07-31-2008
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

TheSqlDataSource.Select(DataSourceSelectArguments. 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.
 
Reply With Quote
 
SAL
Guest
Posts: n/a
 
      07-31-2008

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
>
> TheSqlDataSource.Select(DataSourceSelectArguments. 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.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
re module: Nothing to repeat, but no sre_constants.error: nothing torepeat ? Devin Jeanpierre Python 2 02-14-2012 01:33 PM
Gridview e.OldValues and e.NewValues are nothing Pulkit Sharma ASP .Net Web Controls 4 11-19-2007 04:39 PM
Gridview sorting event - Gridview Datasource always Null .. why??? jobs ASP .Net Web Controls 2 10-24-2006 07:08 AM
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= ASP .Net 1 05-09-2006 06:48 PM
DropDownList.DataSource = Nothing ??? Marc Robitaille ASP .Net 2 07-14-2005 04:48 PM



Advertisments