[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Query ASP.NET Datalist with Drop Down Menu.

Posted on 2012-08-18
Medium Priority
Last Modified: 2012-08-19
I have a menu on my Masterppage and on one of the links I want to retrn the page im seeking (food-drinks.aspx) and at the same time query and return the results in the DataList in food-drinks.aspx.  I want to query the  value "type" in the SqlDatasource.

Thanks  for any assistance.


                    <ul id="menu">
                    <ul id="nav-one" class="dropmenu css-only">

                  <li><a href="#">Tutorials</a></li>
                        <a href="#">Real Estate</a>
                              <li><a href="#">Rental</a></li>
                              <li><a href="#">Purchase</a></li>                               
                  <li><a href="#">place</a></li>


<asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT [id],  [type], [image], [title] FROM [recipe] WHERE ([type] = @type)">
            <asp:ControlParameter ControlID="ListBox1" DefaultValue="type" Name="type"
                PropertyName="SelectedValue" Type="String" />
    <asp:DataList ID="DataList1" runat="server" DataKeyField="id"
        DataSourceID="SqlDataSource1" CellPadding="10" Font-Bold="False"
        Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
        Font-Underline="False" HorizontalAlign="Right" RepeatColumns="5">
        <HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
            Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Justify" />
        <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
            Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Justify" />
            &nbsp;<asp:Label ID="titleLabel" runat="server" Text='<%# Eval("title") %>' />
            <br />
            <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("image") %>'
                Width="140px" />
            <br />
            <asp:HyperLink ID="HyperLink1" runat="server"
                NavigateUrl='<%# String.Format("Recipe.aspx?title={0}", Eval ("title")) %>'
                Text='<%# Bind ("title") %>'> </asp:HyperLink>
            <br />
            <br />
Question by:misnstt
LVL 26

Accepted Solution

Alan Warren earned 2000 total points
ID: 38308753
Hi misnstt,
probably have more control using a stored procedure.
CREATE PROCEDURE [dbo].[Recipe_Sel]
	@Type varchar(50) = NULL
    IF ISNULL(@Type,'') = '' BEGIN
        -- return all records, should never happen if input param is bount to a control param
    	SELECT [id],  [type], [image], [title] 
		FROM [recipe] 
        -- return records matching @Type input param
		SELECT [id],  [type], [image], [title] 
		FROM [recipe] 
		WHERE [type] = @type


-- Testing
-- Return all recipes
-- exec Recipe_Sel 

-- Return Curry recipes
-- exec Recipe_Sel 'Curry'  

Open in new window

Not sure you need the DefaultValue="type", unless you have a recipe [Type] called 'type'.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"  SelectCommand="Recipe_Sel" SelectCommandType="StoredProcedure" >
            <asp:ControlParameter ControlID="ListBox1" Name="type"  PropertyName="SelectedValue" Type="String" />

Open in new window

Alan ";0)

Author Closing Comment

ID: 38309394
Thanks for your fast assistance.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I made this because I wanted to get e-mail with a attached csv file so I'd would be able to import user input into a MS Excel template, but I also wanted to register/save all inputs from each day in a file on the server. 1st - It creates a temp C…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question