Here is the code to fill the subscription length drop down box
protected void ddlMagazine_SelectedIndexChanged(object sender, EventArgs e)
{
//connection
//comand object
//DataReader
SqlConnection connect = new SqlConnection(@"Data Source=.\sqlexpress;initial catalog=MagazineSubscription;integrated security=true");
string sql = "Select SubscriptTypeName, MagDetID "
+ "From subscriptionType st "
+ "Inner Join MagazineDetail md "
+ "On st.SubscriptTypeID=md.SubscriptTypeID "
+ "Where MagID = @MagID";
SqlCommand cmd = new SqlCommand(sql, connect);
cmd.Parameters.AddWithValue("@MagID", int.Parse(ddlMagazine.SelectedValue.ToString()));
SqlDataReader reader;
connect.Open();
reader = cmd.ExecuteReader();
ddlSubscriptionLenght.DataSource = reader;
ddlSubscriptionLenght.DataTextField = "SubscriptTypeName";
ddlSubscriptionLenght.DataValueField = "MagDetID";
ddlSubscriptionLenght.DataBind();
reader.Close();
connect.Close();
}
No comments:
Post a Comment