fill dropdown list by querystring

Posted by KareemSaad on Stack Overflow See other posts from Stack Overflow or by KareemSaad
Published on 2010-04-15T13:28:04Z Indexed on 2010/04/15 16:23 UTC
Read the original article Hit count: 391

Filed under:

I had drop down list and I want to fill it with data by specific condition i used this code but it was,t worked well

<cs>
protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = "ThumbnailViewPage";

    if (Request.QueryString["Category_Id"] != null)
    {
        using (SqlConnection Con = Connection.GetConnection())
        {

            SqlCommand Com = new SqlCommand("GetProducFamilyTP2", Con);
            Com.CommandType = CommandType.StoredProcedure;
            Com.Parameters.Add(Parameter.NewInt("@Category_Id", Request.QueryString["Category_Id"]));
            SqlDataReader DR = Com.ExecuteReader();
            if (DR.Read())
            {
                DDlProductFamily.DataTextField = DR["Name"].ToString();
                DDlProductFamily.DataValueField = DR["ProductCategory_Id"].ToString();
            }
        }

    }
    else if (Request.QueryString["ProductCategory_Id"] != null)
    {
        using (SqlConnection Con = Connection.GetConnection())
        {

            SqlCommand Com = new SqlCommand("GetProducFamilyTP3", Con);
            Com.CommandType = CommandType.StoredProcedure;
            Com.Parameters.Add(Parameter.NewInt("@ProductCategory_Id", Request.QueryString["ProductCategory_Id"]));
            SqlDataReader DR = Com.ExecuteReader();
            if (DR.Read())
            {
                DDlProductFamily.DataTextField = DR["Name"].ToString();
                DDlProductFamily.DataValueField = DR["ProductCategory_Id"].ToString();
            }
        }

    }

}

                                    <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="DDlProductFamily" runat="server" 
                                                ondatabound="DDlProductFamily_DataBound" onload="DDlProductFamily_Load" 
                                                onselectedindexchanged="DDlProductFamily_SelectedIndexChanged">
                                            </asp:DropDownList>
                                        </ContentTemplate>
                                        <Triggers>
                                            <asp:AsyncPostBackTrigger ControlID="DDlProductFamily" EventName="SelectedIndexChanged" />
                                        </Triggers>
                                    </asp:UpdatePanel>

© Stack Overflow or respective owner

Related posts about ASP.NET