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">
                 <SelectParameters>
                    <asp:Parameter  Name="searchwords"  Type="String" />
                </SelectParameters>
           </asp:SqlDataSource>
        
        <br />
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
 AutoGenerateColumns="False">
            <Columns>
                <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" />
            </Columns>
        </asp:GridView>
 
---------------------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)
        {
            GridView1.DataBind();
        }

Open in new window

LVL 2
niceoneishereAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aibusinesssolutionsCommented:
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:
Hello,
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.
aibusinesssolutionsCommented:
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)
         ddl.Items.Add(li)
      Next
   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?
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.