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)
- {
- //int InsuranceId = Convert.ToInt32(grd.DataKeys[e.RowIndex].Values[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;
- }
- //else
- //{
- //}
- con.Close();
- }
- }

Francis SusaimichaelRank #466 · 5.4K reputationPosted May 7, 2018, 2:26 AM EDT
Yogesh VedpathakRank #1,179 · 1.5K reputationPosted May 7, 2018, 3:15 AM EDT
Francis SusaimichaelRank #466 · 5.4K reputationPosted May 10, 2018, 9:45 AM EDT
Deekshaa Singh Chauhan180 reputationPosted May 13, 2018, 11:04 PM EDT
Sankara Krishnan VenugopalRank #833 · 2.7K reputationPosted May 14, 2018, 1:03 AM EDT
Deekshaa Singh Chauhan180 reputationPosted May 9, 2018, 9:40 PM EDT