DropDownList and Stored Procedure

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

Who is Participating?
niceoneishereAuthor Commented:
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.
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.
niceoneishereAuthor Commented:
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 ChristopherCommented:
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?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.