473,414 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

GridView1.DataSource == null ???

Hello,

I have a GridView and an objectDataSource

<asp:GridView ID="GridView1" runat="server"
DataSourceID="ObjectDataSource1" AllowPaging="True" />

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
TypeName="ProductsLib.Business.ProductsBLO"
SelectMethod="SelectProducts"
SortParameterName="sortExpression"></asp:ObjectDataSource>

When I run the app i see a list of products in the gridView. Ok!

Now, i have a button, when I click on it I'd like to display all the
products whose ProductName starts with the letter 'c'

My implementation in the clickevent handler:

DataTable dataTable = GridView1.DataSource as DataTable;

if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.RowFilter = "productname like 'c%'";
dataView.Sort = "productname";
GridView1.DataSource = dataView;

GridView1.DataBind();
}

but my problem is that GridView1.DataSource is null ???

how do i obtain acces to the dataTable?

thank you
Chris
Aug 8 '08 #1
2 13168
Associating data source control to the GridView does not populate DataSource
property at that point. I don't remember does it set the data source or does
it access the result set (by the data source control) directly when
DataBind() is called. BUT In anycase, you can get the result set by calling
data source control's methods e.g ObjectDataSource.Select()
See:
http://msdn.microsoft.com/en-us/libr...ce.select.aspx

Note that the result set cannot possibly be a data table because you are
using a custom business object & ObjectDataSource...
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
"cm****@gmail.com" wrote:
Hello,

I have a GridView and an objectDataSource

<asp:GridView ID="GridView1" runat="server"
DataSourceID="ObjectDataSource1" AllowPaging="True" />

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
TypeName="ProductsLib.Business.ProductsBLO"
SelectMethod="SelectProducts"
SortParameterName="sortExpression"></asp:ObjectDataSource>

When I run the app i see a list of products in the gridView. Ok!

Now, i have a button, when I click on it I'd like to display all the
products whose ProductName starts with the letter 'c'

My implementation in the clickevent handler:

DataTable dataTable = GridView1.DataSource as DataTable;

if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.RowFilter = "productname like 'c%'";
dataView.Sort = "productname";
GridView1.DataSource = dataView;

GridView1.DataBind();
}

but my problem is that GridView1.DataSource is null ???

how do i obtain acces to the dataTable?

thank you
Chris
Aug 9 '08 #2
Unless of course the method returns such, to correct.

Other thing to point out is that GridView does not keep DataSource property
populated over the postbacks (for performance feasons since it would need to
serialize and roundtrip the entire data source)
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
"Teemu Keiski" wrote:
Associating data source control to the GridView does not populate DataSource
property at that point. I don't remember does it set the data source or does
it access the result set (by the data source control) directly when
DataBind() is called. BUT In anycase, you can get the result set by calling
data source control's methods e.g ObjectDataSource.Select()
See:
http://msdn.microsoft.com/en-us/libr...ce.select.aspx

Note that the result set cannot possibly be a data table because you are
using a custom business object & ObjectDataSource...
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
"cm****@gmail.com" wrote:
Hello,

I have a GridView and an objectDataSource

<asp:GridView ID="GridView1" runat="server"
DataSourceID="ObjectDataSource1" AllowPaging="True" />

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
TypeName="ProductsLib.Business.ProductsBLO"
SelectMethod="SelectProducts"
SortParameterName="sortExpression"></asp:ObjectDataSource>

When I run the app i see a list of products in the gridView. Ok!

Now, i have a button, when I click on it I'd like to display all the
products whose ProductName starts with the letter 'c'

My implementation in the clickevent handler:

DataTable dataTable = GridView1.DataSource as DataTable;

if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.RowFilter = "productname like 'c%'";
dataView.Sort = "productname";
GridView1.DataSource = dataView;

GridView1.DataBind();
}

but my problem is that GridView1.DataSource is null ???

how do i obtain acces to the dataTable?

thank you
Chris
Aug 9 '08 #3

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

Similar topics

13
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...
0
by: Jesse Martinez | last post by:
My problem occurs when I use an ArrayList as a ListBox.DataSource. When the ArrayList attached to the Listbox is not empty the Listbox behave normal without problem, but if I remove all items...
4
by: kids_pro | last post by:
Hi, On form_load() I bind a combobox to a dataset and listbox to a datatable. When I want to unbind it I call comboBox1.DataSource = null, listBox1.DataSource = null It unbind but the Items...
1
by: WhiteWizard | last post by:
First my apologies, this may be longer than the normal question. I have a windows app (.NET 2.0, VS2005), and I've written a user control that will allow the user to "drag and drop" a directory...
1
by: Chicagoboy27 | last post by:
It seems when I use GridView1.Columns.Insert(2, nameColumn); to dynamically insert a column into a grid I loose all items that are bound using <asp:TemplateField HeaderText="E-Mail" >...
0
by: Abbas82 | last post by:
Hi, I am working on a GridView control to play a game. I am trying to make the cells editable; however, when I click on edit I lost my data or I get an error: Object reference not set to an...
2
by: shahiz | last post by:
basically im having null pointer exception //read an inputstream is = new DataInputStream(new FileInputStream("test.mpg")); loadBytes(is); //pass it as a datasource for the player public...
0
by: shahiz | last post by:
This the error i get when i try to run my program Error: Unable to realize com.sun.media.amovie.AMController@18b81e3 Basically i have a mediapanel class that initialize and play the media as...
0
by: rajendrsedhain | last post by:
I have problem on Gridview column sorting.I want to sort each column when click to the column head.I implemented the 'GridView1_Sorting methond by using viewstate and in this way below. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.