473,779 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ObjectDataSourc e->Gridview Clear?

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

It binds fine but I need to clear it.
myGridView.Data Source = null:
myGridView.Data Bind();

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 20905
Howdy,

Unfortunatelly, you cannot clear gridview if datasourceid is assigned (from
logical point of view clear operation does not quite make sense). Because
myGridView.Data Source = null:
myGridView.Data Bind();
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.Data Source = new int[0];
myGridView.Data Bind();

and you'll get it. Anyway, i see what you're trying to do. on first page
request, objectdatasourc e 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 btnWhateverClic k(object sender, EventArgs e)
{
myGridView.Data SourceID = String.Empty;
myGridView.Data Source = new int[0];
myGridView.Data Bind();
}

and you're done.

Hope this helps

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

It binds fine but I need to clear it.
myGridView.Data Source = null:
myGridView.Data Bind();

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 "DataSource ID" property instead
of the DataSource(whic h is dedicated for programmatic databinding) to
control the databound control's associated datasource.

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

===============
protected void Button1_Click(o bject sender, EventArgs e)
{
GridView1.DataS ourceID = string.Empty;
GridView1.DataB ind();
}
=============== =

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.comw rote in message
news:%2******** ********@TK2MSF TNGHUB02.phx.gb l...
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 "DataSource ID" property
instead
of the DataSource(whic h is dedicated for programmatic databinding) to
control the databound control's associated datasource.

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

===============
protected void Button1_Click(o bject sender, EventArgs e)
{
GridView1.DataS ourceID = string.Empty;
GridView1.DataB ind();
}
=============== =

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
3868
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 using a GridView that has ViewState enabled, an ObjectDataSource to process the submitted list, textboxes for getting new item data and an add button. Does this approach sound feasible or are there better alternatives? My problem is that I don't...
0
1497
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 connect to my business logic everything works fine. The problem is that I find this quite limited and I need to do some custom work with the parameters, so I am trying to code everything by hand in the code behind. >From a security perspective,...
0
1839
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 { int _id; String _name;
1
1935
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 (PersonFactory) with static methods (Select, Update, Delete, see below). The factory methods work with instances of a simple class (Person, see below). Select and Update works, but the Person object passed to the Delete method is always empty (Id == 0;...
1
2442
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 the table from which the data is coming has a Primary Key field. Gridview is set to edit mode. DataKeyNames = "PK_Field". Now if PK field is not readonly, then data is updated successfully. But if I set PK Field to readonly, then data is not...
0
1659
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 access the object in the OnRowDataBound event am getting a null
0
1248
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 ok. Now what I want is to click on Select Button of DetailView and that row should appear in DetailView, using the same ObjectDataSource, any idea ? I tried using : DetailView1.SelectedValue=GridView1.SelectedDataKey.Value
6
5756
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 on a gridview attached to my ObjectDataSource. Tried all things including build/rebuild. Delete objectdataSource add in again. Still not working. Any info would help
4
6086
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 are being populated. Integers are being passed as 0 and strings are empty regardless of what I changed them to in Edit mode on the GridView. My object method to perform the update:
0
1469
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 the parameters sent to the store proc it all contains NULL. I came across a solution using setting DataKeyNames but i don't have a primary Key ID on the table.The parameters i have are theyear,themonth,code and i want to delete based on those...
0
9633
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
10305
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
10137
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
10074
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
9928
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
8959
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
5373
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
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2867
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.