473,325 Members | 2,805 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,325 software developers and data experts.

Change / set ObjectDataSource paramater at runtime?

Hi All,

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

I'm wondering if it's possible to base the ObjectDataSource 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
ObjectDataSource 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
ObjectDataSource at runtime, and how you'd do that if it is possible?

Many thanks in avance!

Much warmth,

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

May 30 '06 #1
2 12751
Hi Planetthoughtful,

You can configure the ObjectDataSource 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:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetCustomers"
TypeName="Customers">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" DefaultValue="*"
Name="filter" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:ObjectDataSource>

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

ObjectDataSource1.SelectParameters[0].DefaultValue = "<your value>";

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

"planetthoughtful" wrote:
Hi All,

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

I'm wondering if it's possible to base the ObjectDataSource 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
ObjectDataSource 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
ObjectDataSource at runtime, and how you'd do that if it is possible?

Many thanks in avance!

Much warmth,

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

May 30 '06 #2
You can configure the ObjectDataSource 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:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetCustomers"
TypeName="Customers">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" DefaultValue="*"
Name="filter" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:ObjectDataSource>

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

ObjectDataSource1.SelectParameters[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
ObjectDataSources as well!

Thanks again!

Much warmth,

planetthoughtful
---
"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
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...
3
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...
1
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...
1
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...
0
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...
0
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...
2
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...
0
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...
9
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.