How to check selected dropdown value is available in database
When we select commodity from dropdaown and this value is not in database with this warehouse it does not show any message .
- protected void ddlCommodity_SelectedIndexChanged(object sender, EventArgs e)
- {
- Int64 Cmdty = Convert.ToInt64(ddlCommodity.SelectedItem.Value);
- if ((Convert.ToInt32(ddlWarehouse.SelectedItem.Value)) != 0)
- {
-
- string constr = WebConfigurationManager.ConnectionStrings["WarehouseWebsiteString"].ConnectionString;
-
- using (SqlConnection con = new SqlConnection(constr))
- {
- using (SqlCommand cmd = new SqlCommand("Select CommodityId from tblCommodityonWarehouse WHERE WarehouseId = @WarehouseId"))
- {
- cmd.Parameters.AddWithValue("@CommodityId", Cmdty);
- cmd.Parameters.AddWithValue("@WarehouseId", ddlWarehouse.SelectedIndex);
- cmd.Connection = con;
- con.Open();
- int k = cmd.ExecuteNonQuery();
- if (k > 0)
- {
- string popupScript = "$.prompt('This Commodity is Not Available. Please use another.');";
- ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "clientScript", popupScript, true);
- ddlCommodity.SelectedIndex = -1;
- }
-
-
-
-
- con.Close();
- }
-
- }