fill dropdown list by querystring
- by KareemSaad
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>