I have a GridView that works fine when I bind it to an ObjectDataSourc e at
design time. But if I bind it at run time nothing happens.
On a button click event I say...
GridView1.DataS ourceID = ObjectDataSourc e1.ID;
GridView1.DataB ind();
What's missing?
--
Regards,
Gary Blakely 5 2807
Hi Gary,
Thank you for your post.
This behavior is by design. Normally when you are using declarative
databinding, you set datasource using DataSourceID; when you are setting
datasource at runtime, you set it using DataSource and call DataBind:
GridView1.DataS ource = ObjectDataSourc e1;
GridView1.DataB ind();
Hope this helps. Please feel free to post here if anything is unclear.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support
=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Walter, again, thanks for responding.
Looks like my binding failue was due to some previous state of the GridView.
after I dropped a fresh GridView your code worked fine.
BUT, that's not really what I am getting at....
I not only want to bind in code but I want to set all the Enable Editing,
Deleting, Selection, Paging, Sorting features in code but I can't see how to
EnableEditing at run time.
I tried to drop a new GridView on the page and then, at design time, added
the Edit and Delete buttons. then bound it at run time but when I hit an
Edit button I got an exception saying "GridView1 fired event RowEditing
which was not handled.
The answer to WHY do I want to do this is because I would like to have one
GridView on the form that will update a number of datasources depending upon
selections by the user.
--
Regards,
Gary Blakely
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:g%******** **********@TK2M SFTNGXA01.phx.g bl...
Hi Gary,
Thank you for your post.
This behavior is by design. Normally when you are using declarative
databinding, you set datasource using DataSourceID; when you are setting
datasource at runtime, you set it using DataSource and call DataBind:
GridView1.DataS ource = ObjectDataSourc e1;
GridView1.DataB ind();
Hope this helps. Please feel free to post here if anything is unclear.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support
=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no
rights.
Hi Gary,
Thank you for your update.
To perform v1-style databinding and editing using GridView, you need to
handle the ItemCommand event to capture the Edit command (just like you
handled the EditCommand event using DataGrid). You also need to re-databind
the GridView after changing the EditIndex in order to cause the grid to
re-render the data in edit mode. Same as DataGrid.
protected void GridView1_RowCo mmand(object sender, GridViewCommand EventArgs
e) {
if (e.CommandName == "Edit") {
GridView1.EditI ndex = Int32.Parse(e.C ommandArgument. ToString());
GridView1.DataS ource = ObjectDataSourc e1;
GridView1.DataB ind();
}
}
Also, you must handle many required events when setting DataSource at
runtime.
However, you could probably avoid all this work by simply making your
DataSource available through an ObjectDataSourc e control and then
databinding the GridView using DataSourceID instead of the v1-style
approach.
Since you mentioned you're using one GridView to update several
DataSources, I suppose you're still updating a DataSource at one time.
I suggest you to use one ObjectDataSourc e, but create the Select, Delete,
Update, Insert methods with one additional parameter to distinguish the
user's selection. When you declare the ObjectDataSourc e in ASPX, you can
use the <UpdateParamete rs>, <DeleteParamete rs>, etc. to include a
ControlParamete r which references the control that represents user's
selection. In ObjectDataSourc e's methods, you will know which data source
is expected to access.
Hope this helps. Please feel free to post here if anything is unclear.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support
=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Some sample code (only update method is demostrated here):
<asp:DropDownLi st ID="ddlChoice" runat="server"> </asp:DropDownLis t>
<asp:ObjectData Source TypeName="MyNam espace.MyOds"
UpdateMethod="U pdateData" ID="ods1" runat="server">
<UpdateParamete rs>
<asp:ControlPar ameter Name="dataSourc eType"
ControlID="ddlC hoice" PropertyName="S electedValue" Type="Int32" />
</UpdateParameter s>
</asp:ObjectDataS ource>
Suppose the method MyOds.UpdateDat a() has first parameter set to "int
dataSourceType" . And the DropDownList's SelectedValue property is binding
to an Int32 which represents selected dataSourceType.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support
=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Gary,
Please feel free to post here if anything is unclear or you need more
detailed sample code.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support
=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: sck10 |
last post by:
Hello,
I have a GridView that is using the following to connect to a SQL Server
2000 stored procedure:
<asp:SqlDataSource
ID="dsWebDocList" SelectCommand="sp_web_WebDocument"
ConnectionString="<%$ ConnectionStrings:cnnSQL_Connect %>" Runat="server">
<SelectParameters>
<asp:Parameter Type="String" DefaultValue="FindWebDocAll"
|
by: Hans Merkl |
last post by:
Hi,
I was wondering if it's possible to bind the header text of a GridView
column to a method of an object I have. At the moment I am setting the
header texts in Page_Load but I was wondering if I can do with databinding.
thanks
Hans Merkl
|
by: Smash |
last post by:
I have problem binding gridview....
At first i didn't want to bind gridview at first page load...so in my
objectdatasource_selecting event i wrote this:
If Not Page.IsPostBack Then
e.Cancel = True
End If
Thats solved the problem for the first bind....
|
by: mateo |
last post by:
Hello,
I have a GridView inside which i want to show 3 dropdownList (one for
each Column).
So i've created 3 TemplateField
Continent
Country
City
|
by: Amit |
last post by:
Hello,
I have a simple search screen, with two drop-downs and a text box. There's
also a GridView control that is using a SqlDataSource control to show the
matching results. The SqlDataSource uses the control values in its query as
parameters. Two questions:
1. When the Find button is clicked, how do I tell the GridView to load the
data?
2. How do I stop the GridView from data binding when the page first loads? I
don't want to...
| |
by: AG |
last post by:
ASP.NET 2.0, VS 2005
I have a gridview with paging enabled, bound to an objectdatasource.
Both were dropped on to the page and configured via the wizards.
Basically working as expected.
The gridview's databind method is apparently called when the page is loaded
as I have no code calling the databind method.
How can I keep the gridview from databinding automatically and control it
myself?
|
by: Mike |
last post by:
I'm having trouble getting a gridview to bind. I probably missing something
completely obvious and would appreciate any help on offer.
I'm passing parameters via querystring, and have created a stored proc as
follows:
qGetSearchResults:
SELECT
Adverts.AdvertID,
|
by: RobertTheProgrammer |
last post by:
Hi folks,
I've got another problem. Basically, I'm trying to use a nested GridView, however the nexted GridView displays no values (even though in debug I'm getting valid values into my DataSet. It's probably a binding issue somewhere, but I'm not sure where.
Here's the ASP (slightly edited to remove verbosity):
<asp:GridView ID="GridViewMain" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999"
...
|
by: Sobin Thomas |
last post by:
Hi All,
How can I bind the Gridview control to Sql Datasource control on a button
click(I see majority of the articles binding datasource at page load) I need
to enable the paging and sorting of the Gridview control also .Actually I am
able to bind the sql datasource control to the Gridview on button Click but
on clicking the GridView for paging or sorting , the Gridview vanishes!!
In short,
I want to bind the GridView control to a...
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |