Bryan Gomez

Bryan Gomez

  • 1.8k
  • 21
  • 17.3k

How set value of DropDown after getting the list

Nov 19 2017 10:57 PM
I need to set value of the dropdown after getting the list for dataset. But I'm having an error of:

The ViewData item that has the key 'txtCustomer' is of type 'System.String' but must be of type 'IEnumerable<SelectListItem>'

Here's my Controller:
  1. wmsSR = new WMSSOFT_WCF_Service.WMSSOFT_InterfaceClient();  
  2. dsl = new DataSet();  
  3. dsO = new DataSet();  
  4. a = "GetSRMCustomers";  
  5. b = string.Empty;  
  6.   
  7. //b = wmsSR.fCallWMSSOFTService(a, null, ref dsl, ref dsO);  
  8. b = wmsSR.fCallWMSSOFTService(a, ""ref dsl, ref dsO);  
  9.   
  10. if (b == "OK ~~")  
  11. {  
  12.     if (dsO.Tables[0].Rows.Count >= 0)  
  13.     {  
  14.         List<SelectListItem> item = new List<SelectListItem>();  
  15.         for (int i = 0; i < dsO.Tables[0].Rows.Count; i++)  
  16.         {  
  17.             item.Add(new SelectListItem { Text = dsO.Tables[0].Rows[i]["NAMECUST"].ToString(), Value = dsO.Tables[0].Rows[i]["IDCUST"].ToString().Replace("  ", String.Empty) });  
  18.         }  
  19.   
  20.         ViewBag.txtCustomer = item; 

  21.         ViewBag.txtCustomer = "ABC ";  
  22.     }  


Answers (5)