473,386 Members | 1,602 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,386 software developers and data experts.

ObjectDataSource->Gridview Clear?

I have an objectdatasource reading a dataset and I have a gridview using
that objectdatasource (at design time).

It binds fine but I need to clear it.
myGridView.DataSource = null:
myGridView.DataBind();

does not work! There is no clear method for the ODS. How do I get rid of
it?

--
Regards,
Gary Blakely
Feb 12 '07 #1
4 20863
Howdy,

Unfortunatelly, you cannot clear gridview if datasourceid is assigned (from
logical point of view clear operation does not quite make sense). Because
myGridView.DataSource = null:
myGridView.DataBind();
is simply ignored, you are not getting 'Both DataSource and DataSourceID are
defined on "myGridView". Remove one definition.' exception. But try binding
with empty data source i.e.

myGridView.DataSource = new int[0];
myGridView.DataBind();

and you'll get it. Anyway, i see what you're trying to do. on first page
request, objectdatasource is used to populate gridview (remember it happens
in gridviews's onprerender method that raises PreRender event), and then on
postback, you want to clear the gridview:

protected void btnWhateverClick(object sender, EventArgs e)
{
myGridView.DataSourceID = String.Empty;
myGridView.DataSource = new int[0];
myGridView.DataBind();
}

and you're done.

Hope this helps

--
Milosz
"GaryDean" wrote:
I have an objectdatasource reading a dataset and I have a gridview using
that objectdatasource (at design time).

It binds fine but I need to clear it.
myGridView.DataSource = null:
myGridView.DataBind();

does not work! There is no clear method for the ODS. How do I get rid of
it?

--
Regards,
Gary Blakely
Feb 12 '07 #2
Hello Gary,

For those ASP.NET 2.0 DataBound controls, since it provides a new
DataSource control bound model(you can add the binding relation at
design-time or runtime), you should use the "DataSourceID" property instead
of the DataSource(which is dedicated for programmatic databinding) to
control the databound control's associated datasource.

So for your scenario, since you've choosed an objectdatasource for your
GridView at design-time, the DataSource control ID has been save in the
GridView's DataSourceID property. In sequential requests(include
postback), even if you manually change GridView.DataSource, Gridview will
still use the "DataSourceID" (the associated datasouce control) to populate
data collection. Thus, you can simply change Gridview.DataSourceID to
empty string and call databind to clear it. e.g.

===============
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.DataSourceID = string.Empty;
GridView1.DataBind();
}
================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 12 '07 #3
Oh yes, now I remember.
Thanks much !

--
Regards,
Gary Blakely
Dean Blakely & Associates
www.deanblakely.com
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:%2****************@TK2MSFTNGHUB02.phx.gbl...
Hello Gary,

For those ASP.NET 2.0 DataBound controls, since it provides a new
DataSource control bound model(you can add the binding relation at
design-time or runtime), you should use the "DataSourceID" property
instead
of the DataSource(which is dedicated for programmatic databinding) to
control the databound control's associated datasource.

So for your scenario, since you've choosed an objectdatasource for your
GridView at design-time, the DataSource control ID has been save in the
GridView's DataSourceID property. In sequential requests(include
postback), even if you manually change GridView.DataSource, Gridview will
still use the "DataSourceID" (the associated datasouce control) to
populate
data collection. Thus, you can simply change Gridview.DataSourceID to
empty string and call databind to clear it. e.g.

===============
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.DataSourceID = string.Empty;
GridView1.DataBind();
}
================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Feb 12 '07 #4
You're welcome.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Feb 13 '07 #5

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

Similar topics

1
by: John_H | last post by:
Re: ASP.NET 2.0 I would like suggestions or code examples on how to collect a variable length list of input data (item# & item quantity specifically). I thought that I could accomplish this...
0
by: Eiriken | last post by:
Hello everyone, I am using ASP.NET 2 and trying to bind a objectdatasource to a gridview. By doing this the most common way by adding an objectdatasource to the page and by using the wizard to...
0
by: David Hubbard | last post by:
I am using a GridView to display a set of objects that have a parent-child relationship. Each object, MyBO, has an ID property that is used to get the children of that object. class MyBO { ...
1
by: Jürgen Bayer | last post by:
Hi, I just tried out the ObjectDataSource of ASP.NET 2.0. A simple application works with a GridView bound to an ObjectDataSource. The ObjectDataSource is set to a (factory) class...
1
by: Raja | last post by:
Hi Everybody Just playing with ObjectDataSource and noticed the following. I have a Gridview which binds to a ObjectDataSource. ObjectDataSource gets data from a typed dataset created with VWD. In...
0
by: Dom | last post by:
Hello This should work I know ... but.. with your help perhaps.. Trying to assign a 'selectparameter' to an objectdatasource nested within a gridview EditItemTemplate. When I try to access...
0
by: Luqman | last post by:
I have used a single objectDataSource for GridView and DetailView, and when I load the page, the GridView shows all the entries of Invoice, and DetailView shows the 1st entry of Invoice, thats all...
6
by: =?Utf-8?B?V2F5RG93blVuZGVy?= | last post by:
When I link an ObjectDataSource to a business object, it appears that the Refresh Schema button does nothing. I have added a property to the business object and want to display this new property...
4
by: tim.cavins | last post by:
I have a GridView populated by an ObjectDataSource. I am having issues passing the parameters to the objectdatasource. I have verified that the method is being called but none of the parameters...
0
by: Rote Rote | last post by:
Hi Guys, I have a simple Edit,Update Gridview and i'm using ObjectDatasource with dataset generated and TableAdapters I can do an update no problem. But can't get my delete to work. When i look at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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,...
0
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...
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...

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.