Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
I have two comboboxes were in combobo1 i have data of hospitals and linked hospital users to combobox but while i running the outpit i amnot getting exact list of users who all under certain hopspital, how can we get the same

What I have tried:

void CmbHospitalsSelectedIndexChanged(object sender, EventArgs e)
		{
			            try
            {
                
                //string tag = ((KeyValuePair< string, string >)cmbHospitals.SelectedItem).Key; 
               //MessageBox.Show(tag);            
               // var s=cmbHospitals.SelectedItem;
                //MessageBox.Show(s.key);
                //For Hospital users Dropdown Clear Start
                   dynamic refobj = cmbHospitals.SelectedItem;
                    int key=(int) refobj.Key;
                    Text= Text+cmbhusers.DisplayMember;
                    
					//MessageBox.Show(refobj.Key);
                    cmbhusers.SelectedIndex = -1;
                    cmbhusers.Items.Clear();

                // End Clear
                if(true)
                {
                    WebClient wc = new WebClient();
                    wc.Headers["Content-type"] = "application/x-www-form-urlencoded";
                    NameValueCollection collection = new NameValueCollection();
                    collection.Add("hid",cmbHospitals.SelectedIndex.ToString());
                    collection.Add("sno", "4");
                    byte[] bret = wc.UploadValues(URLAuth, collection);
                    string sret = "";
                    sret = System.Text.Encoding.ASCII.GetString(bret);
                    int count=0;
                    string[,] husers ;                
                   
                     if (sret != "")
                    {                       
                        XmlDocument readDoc = new XmlDocument();
                        readDoc.LoadXml(sret);
                        count = readDoc.SelectNodes("hospitalusers/huids").Count;
                        husers = new string[count, 2];      
                         // alternately, _doc.Load( _strFilename); to read from a file.
                        XmlNodeList xhuid = readDoc.GetElementsByTagName("huid");
                        XmlNodeList xuser_name = readDoc.GetElementsByTagName("user_name");
                        for (int i= 0; i < count; i++)
                        {
                            husers[i,0] = xhuid[i].InnerText;
                            husers[i, 1] = xuser_name[i].InnerText;
                        }
                           cmbhusers.DisplayMember="text";
                             cmbhusers.ValueMember="key";    
                             
                        for (int i = 0; i < husers.GetLength(0); i++)
                        {
                            cmbhusers.Items.Add(new { text = husers[i, 1], key=Convert.ToInt16(husers[i,0])});
                        }
                     }
                }
            }
Posted
Updated 30-Apr-18 1:13am

1 solution

I got the solution by using dynamic reference
dynamic refobj = cmbhpd.SelectedItem;
                   int key=(int) refobj.Key;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900