We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


DropDownList and Stored Procedure

Medium Priority
Last Modified: 2013-11-26
Hi Experts,
i have a stored procedure which i am using to provide search feature in my website. i am passing the value the user enters in textbox to the SP and displaying the results in GridView. one of the field in the GridView is a field called Size. i want this field to be DropDrowList, so that all the sizes of a particular item are displayed there. how can i do this. any please is appreciated . here is my code.

FISRT: aspx page:
<div class="search">
<asp:TextBox id="TextBox1" runat="server"  />
<asp:Button ID="Button1" runat="server" Text="search" OnClick="Button1_Click" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MySiteConn %>" 
 SelectCommand="MyProcedure" SelectCommandType="StoredProcedure" OnSelecting="SqlDataSource1_Selecting">
                    <asp:Parameter  Name="searchwords"  Type="String" />
        <br />
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
                <asp:BoundField DataField="ItemNumber" HeaderText="ItemNumber" SortExpression="ItemNumber" />
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
                <asp:BoundField DataField="Size" HeaderText="Name" SortExpression="Size" />
---------------------CODE BEHIND------------------------------
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
               e.Command.Parameters["@searchwords"].Value = TextBox1.Text;
        protected void Button1_Click(object sender, EventArgs e)

Open in new window

Watch Question

Convert the boundfield Size to a template field, and then edit the template.  Add a dropdownlist and either add the other sizes manually, or bind it to a datasource that contains the additional sizes.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


my question is how to bind the dropdownlist to the stored procedure to the sizes of the items are that being returned by the stored procedure when a user searches. ( all the sizes are stored in the database and they are different from one item to another ) so i dont think i can add them manually.
i hope i am clear in explaining my problem. i do know how to convert the bound field to a template field and add a ddl.
Thanks i appreciate it.
Ok, so each dropdownlist will have different values?

I'm thinking the best way to do that would be to convert it to a template, then add code to the RowDataBound function.  Something like this:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
   If e.Row.RowType = DataControlRowType.DataRow Then
      Dim ddl As DropDownList = e.Row.FindControl("DropDownList1")
      'add some code to get data from Stored Procedure
      For Each item In DataRows
         Dim li As New ListItem(item)
   End If
End Sub

Open in new window

Obadiah ChristopherDeveloper User Interface

Can u show how the data is being fetched from the stored procedure.

How are you planning to return all the sizes for the record?
Hello All,
i just did it by creating a separate stored procedure which would get me just the item number and sizes and used this as the data source for the DDL.
Thanks guys i appreciate your help.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.