By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,830 Members | 1,722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,830 IT Pros & Developers. It's quick & easy.

How to pass parameter to DataSet via user control?

P: n/a

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.WhateverTableAdapt er">
<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
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.uwnSt affArticlesTableAdapter">
<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.D ataTable1TableAdapter">
</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" />


<ke*****@u.washington.edu> wrote in message
news:eg**************@TK2MSFTNGP15.phx.gbl...

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.WhateverTableAdapt er">
<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

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.