ankit gaur

ankit gaur

  • 1.4k
  • 298
  • 32.6k

Dropdown list value and text issue

Nov 6 2020 6:18 AM
Hello,
 
this is my code to save the record into database
  1. SqlCommand cmd = new SqlCommand("INSERT INTO ABC (ComplainerName," +  
  2. " ComplainerAddress,ComplainerMobile,ComplaintFor," +  
  3. " BuildingDevelopment,PlantMachCategory,PlantMachSubCategory,PlantMachItem,ItemIdentification)" +  
  4. " VALUES(@lblnamea,@lblFlatno,@lblMobile,@ComplaintFor,@BuildingDevelopment,@ddlAssetCat," +  
  5. " @ddlAssetSubCat,@ddlAssetItem,@ddlItemIdentification)");  
  6. cmd.Parameters.AddWithValue("@lblnamea", lblMeter.Text);  
  7. cmd.Parameters.AddWithValue("@lblFlatno", lblFlatno.Text);  
  8. cmd.Parameters.AddWithValue("@lblMobile", lblMobile.Text);  
  9. cmd.Parameters.AddWithValue("@ddlAssetCat", ddlAssetCat.SelectedValue);  
  10. cmd.Parameters.AddWithValue("@ddlAssetSubCat", ddlAssetSubCat.SelectedValue);  
  11. cmd.Parameters.AddWithValue("@ddlAssetItem", ddlAssetItem.SelectedValue);  
  12. cmd.Parameters.AddWithValue("@ddlItemIdentification", ddlItemIdentification.SelectedValue);  
i did save the value in sql database
 
ddlAssetCat.SelectedValue,dlAssetSubCat.SelectedValue,ddlAssetItem.SelectedValue,ddlItemIdentification.SelectedValue
 
Now i m showing the record into gridview but i want to show the DataTextField text.
 
Like ddlAssetCat value is 2 but DataTextField is Eletrical .
 
I want to show the Eletrical in gridview
  1. using (SqlCommand cmd = new SqlCommand("SELECT [ComId],[ComplainerName],[ComplainerAddress]," +  
  2. " [ComplainerMobile],[ComplaintFor],[BuildingDevelopment],[PlantMachCategory]," +  
  3. " [PlantMachSubCategory],[PlantMachItem],[ItemIdentification] "))  
  4. {  
  5. using (SqlDataAdapter sda = new SqlDataAdapter())  
  6. {  
  7. cmd.Connection = myconn;  
  8. sda.SelectCommand = cmd;  
  9. using (DataTable dt = new DataTable())  
  10. {  
  11. sda.Fill(dt);  
  12. GrdComplaintkList.DataSource = dt;  
  13. GrdComplaintkList.DataBind();  
  14. DataView dv = dt.DefaultView;  
  15. GrdComplaintkList.DataSource = dv;  
  16. GrdComplaintkList.DataBind();  
  17. }  
  18. }  
  19. }  
Please help

Answers (2)