473,769 Members | 2,246 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 20903
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
1496
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
2440
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
1247
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
5754
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
6084
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
1468
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
9422
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10035
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
9984
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,...
1
7403
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
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
5293
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
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
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
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.