473,651 Members | 3,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change / set ObjectDataSourc e paramater at runtime?

Hi All,

I have an ASP.NET page that displays a GridView control based on an
ObjectDataSourc e control.

I'm wondering if it's possible to base the ObjectDataSourc e in question
on a parameter query, with the ability to set the parameter value at
run time (in the Page_Load event, perhaps?)?

Basically, I'd like to display records in the GridView based on values
typed into a text box. So, I guess I'm looking to base the
ObjectDataSourc e on a SELECT query similar to:

SELECT column1, column2, column3 FROM table1 WHERE column1 = @col1val;

Can anyone tell me if it's possible to set a parameter for an
ObjectDataSourc e at runtime, and how you'd do that if it is possible?

Many thanks in avance!

Much warmth,

planetthoughtfu l
---
"Lost in thought"
http://www.planetthoughtful.org

May 30 '06 #1
2 12787
Hi Planetthoughtfu l,

You can configure the ObjectDataSourc e to get its contents from a control on
the page. Select configure data source in the Gridview action list an run
through the wizard, selecting Control as the parameter type, or modify the
HTML like this:

<asp:ObjectData Source ID="ObjectDataS ource1" runat="server"
SelectMethod="G etCustomers"
TypeName="Custo mers">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Text Box1" DefaultValue="* "
Name="filter" PropertyName="T ext"
Type="String" />
</SelectParameter s>
</asp:ObjectDataS ource>

Use something like this if you want to dynamically set it in code:

ObjectDataSourc e1.SelectParame ters[0].DefaultValue = "<your value>";

Joe
http://www.csharp-station.com

"planetthoughtf ul" wrote:
Hi All,

I have an ASP.NET page that displays a GridView control based on an
ObjectDataSourc e control.

I'm wondering if it's possible to base the ObjectDataSourc e in question
on a parameter query, with the ability to set the parameter value at
run time (in the Page_Load event, perhaps?)?

Basically, I'd like to display records in the GridView based on values
typed into a text box. So, I guess I'm looking to base the
ObjectDataSourc e on a SELECT query similar to:

SELECT column1, column2, column3 FROM table1 WHERE column1 = @col1val;

Can anyone tell me if it's possible to set a parameter for an
ObjectDataSourc e at runtime, and how you'd do that if it is possible?

Many thanks in avance!

Much warmth,

planetthoughtfu l
---
"Lost in thought"
http://www.planetthoughtful.org

May 30 '06 #2
You can configure the ObjectDataSourc e to get its contents from a control on
the page. Select configure data source in the Gridview action list an run
through the wizard, selecting Control as the parameter type, or modify the
HTML like this:

<asp:ObjectData Source ID="ObjectDataS ource1" runat="server"
SelectMethod="G etCustomers"
TypeName="Custo mers">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Text Box1" DefaultValue="* "
Name="filter" PropertyName="T ext"
Type="String" />
</SelectParameter s>
</asp:ObjectDataS ource>

Use something like this if you want to dynamically set it in code:

ObjectDataSourc e1.SelectParame ters[0].DefaultValue = "<your value>";


Hi Joe,

Thanks for this answer! I managed to work my way around this problem in
the interim by using an SqlDataSource for the GridView, and explicitly
setting the SELECT statement with a variable value in the WHERE clause,
but it's great to know how to achieve the same thing using
ObjectDataSourc es as well!

Thanks again!

Much warmth,

planetthoughtfu l
---
"Lost in thought"
http://www.planetthoughtful.org

May 30 '06 #3

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

Similar topics

5
1975
by: Ole M | last post by:
I'm having some trouble using the ObjectDataSource in ASP.NET 2.0. I have a wrapper that contains the static methods for Select and Update. The Update-method takes the business object as parameter. When the Update-method is invoked by the ObjectDataSource, the object referenced is not the same object returned by the Select-method, but a new object with only the values from the Edit-template. So basically I get a reference to a useless...
3
6879
by: Robert | last post by:
What is the best way to pass a parameter to an ObjectDataSource. I am able to add a new parameter to the SelectParameters, but I would like to just assign a value to an existing parmeter at runtime. Currently I am just adding the parameter at runtime and setting the value: ObjectDataSource1.SelectParameters.Add("searchCCN", "") I would like to accomplish the following: ObjectDataSource1.SelectParameters.("LastName") = "Doe"
1
2490
by: Scott F K Hooper | last post by:
VB.NET 2.0 project... I have an Access database with a table that has one primary key. I have used the Add TableAdapter wizard in VS2005 to create my TableAdapter. Next I added an ObjectDataSource object to a new aspx form, chosen the newly created TableAdapter and selected the parameterised Update command from the drop list provided. Finally I added a GridView control and bound it to the ODS. The problem I have is an error I get when...
1
2771
by: Scott F K Hooper | last post by:
My ASP.NET 2.0 project has a GridView that I want to be able to edit and update records with. The GridView has been bound to an ObjectDataSource control that has the following Update method signature: Update(Nullable<Int32> Tile_Number, String Tile_Name, String Tile_Path, Nullable<Decimal> Value, Boolean Sold, Boolean Payment_Verified, Nullable<Byte> Owner_Type, String Line_1, String Line_2, String First_Name, String Last_Name, String...
0
1313
by: John Davis | last post by:
Hi all, hope you are well. I would like to know if I can access the strongly typed properties of my datatable when binding through the ObjectDataSource object. I am currently creating some hyperlinks in a repeater bound to an objectdatasource with the following code: <asp:HyperLink runat="server" ID="HyperLink1" NavigateUrl='<%# string.Format("~/Products.aspx?page=0&categoryId={0}",
0
1378
by: John Davis | last post by:
Hi all, hope you are well.(not sure if this posted the first time) I would like to know if I can access the strongly typed properties of my datatable when binding through the ObjectDataSource object. I am currently creating some hyperlinks in a repeater bound to an objectdatasource with the following code: <asp:HyperLink runat="server" ID="HyperLink1" NavigateUrl='<%# string.Format("~/Products.aspx?page=0&categoryId={0}",
2
8747
by: Philip | last post by:
I can use a GridView and ObjectDataSource to bind my data using "Eval" expressions ... provided the GridView and related Column TemplateFields are defined as inline HTML. I prefer to programmatically create the GridView Column/ TemplateField definitions at runtime.... because I do not know the number of applicable columns until runtime. The addition of the GridView Column/ TemplateFields work fine, however the "Eval" expressions do not...
0
2764
by: =?Utf-8?B?Z292ZXI=?= | last post by:
Hello, I have a Formview in insert mode with a fileUpload control on it. I'm trying to get the contents of the uploaded file passed to my ObjectDataSource to be persisted to my database. The Method called by the Insert method takes a parametare called DocBlob of type byte for the file contents. When I generate an object datasource using this method, it generates the parameter below: <asp:Parameter Name="DocBlob" Type="Object" /> Now...
9
8820
by: Kernel Bling | last post by:
Hi Everyone, This Saturday the stage was set. The problem simply could not go on existing -- it had to be solved. Many hours, articles, compilations and frustrations later I still did not find an answer. Even pacing around my flat until I nearly went into an altered state of reality proved futile. So here is the problem... When I link up the ObjectDataSource UpdateMethod to a method in the
0
8357
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
8803
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...
1
8465
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
6158
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
4144
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
4285
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
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
1
1910
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
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.