How to pass parameter to DataSet via user control?

G

Guest

Hi,

I've defined an ObjectDataSource and a parameterized DataSet. I would like
it if I could pass the parameter value that describes the query that creates
the DataSet as part of a user control declaration. Here's how the parameter
is described in the context of my ObjectDataSource:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetArticlesByWhomever"
TypeName="WhateverTableAdapters.WhateverTableAdapter">
<SelectParameters>
<asp:parameter DefaultValue="83" Name="PersonID" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

The query that's part of the DataSet has a standard @Parameter string, and
I've verfied that it is working with the DefaultValue I'm passing.

Can somone tell me how to set a differnet Parameter value using a value
passed from a User Control and/or programmatically?

Thanks,

-KF
 
G

Guest

Answering my own question: here's 3/4 of the answer. I am still figuring out
how to pass a parameter directly from the user control to the query that
defines the ObjectDataSource -- if someone could answer that, I'd appreciate
it. For anyone looking for a simple example of how ObjectDataSource can be
parameterized, example follows.

-KF

Steps:
1) Configure your ObjectDataSource query to accept a parameter
2) Include a <asp:ControlParameter ... (nested as a SelectParameter) that
includes a default value you wish to pass and a binding to a ControlID.

Elaborating that:
1) SELECT Contentitems.Con_Title, ...
WHERE ( (Contentitems.Sta_StatusID <> 666 ) AND ...
(Persons.Per_PersonID = @PersonID)


2)
<asp:ObjectDataSource ID="odsArticlesByStaff" runat="server"
OnSelecting="ObjectDataSource1_Selecting"
SelectMethod="GetArticlesByUwnewsStaff"
TypeName="ArticlesByUwnewsStaffTableAdapters.uwnStaffArticlesTableAdapter">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" DefaultValue="83"
Name="PersonID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsUwnewsStaff" runat="server"
SelectMethod="GetNewsReleaseAuthorsDT"
TypeName="uwnews_NewsReleaseAuthorsTableAdapters.DataTable1TableAdapter">
</asp:ObjectDataSource>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="odsUwnewsStaff" DataTextField="Per_SurName"
DataValueField="Per_PersonID">
<asp:ListItem Value="83">Name1</asp:ListItem>
<asp:ListItem Value="1">Name2</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="submit" />
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top