Deekshaa Singh Chauhan

Deekshaa Singh Chauhan

  • 1.7k
  • 178
  • 11.1k

how to check selected dropdown value is exists or not

May 7 2018 6:20 AM
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 .
 
 
  1. protected void ddlCommodity_SelectedIndexChanged(object sender, EventArgs e)  
  2.     {  
  3.         Int64 Cmdty = Convert.ToInt64(ddlCommodity.SelectedItem.Value);   
  4.         if ((Convert.ToInt32(ddlWarehouse.SelectedItem.Value)) != 0)  
  5.         {  
  6.             //int InsuranceId = Convert.ToInt32(grd.DataKeys[e.RowIndex].Values[0]);  
  7.             string constr = WebConfigurationManager.ConnectionStrings["WarehouseWebsiteString"].ConnectionString;  
  8.   
  9.             using (SqlConnection con = new SqlConnection(constr))  
  10.             {  
  11.                 using (SqlCommand cmd = new SqlCommand("Select CommodityId from tblCommodityonWarehouse WHERE WarehouseId = @WarehouseId"))  
  12.                 {  
  13.                     cmd.Parameters.AddWithValue("@CommodityId", Cmdty);  
  14.                     cmd.Parameters.AddWithValue("@WarehouseId", ddlWarehouse.SelectedIndex);  
  15.                     cmd.Connection = con;  
  16.                     con.Open();  
  17.                     int k = cmd.ExecuteNonQuery();  
  18.                     if (k > 0)  
  19.                     {  
  20.                         string popupScript = "$.prompt('This Commodity is Not Available. Please use another.');";  
  21.                         ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "clientScript", popupScript, true);  
  22.                         ddlCommodity.SelectedIndex = -1;  
  23.                     }  
  24.                     //else  
  25.                     //{  
  26.   
  27.                     //}  
  28.                     con.Close();  
  29.                 }  
  30.   
  31.             }  

Answers (6)