hi
i have written below code to get values in combobox nut i am getting error as object reference not set .please suggest
- void CmbhospitalsSelectedIndexChanged(object sender, EventArgs e)
- {
- try
- {
- WebClient wc = new WebClient();
- wc.Headers["Content-type"] = "application/x-www-form-urlencoded";
- NameValueCollection collection = new NameValueCollection();
- collection.Add("hid","0");
- collection.Add("sno", "2");
- byte[] bret = wc.UploadValues(URLAuth, collection);
- string sret = "";
- sret = System.Text.Encoding.ASCII.GetString(bret);
- int count=0;
- string[,] hospitalslist ;
-
- if (sret != "")
- {
- XmlDocument readDoc = new XmlDocument();
- readDoc.LoadXml(sret);
- count = readDoc.SelectNodes("hoskeys/hkids").Count;
- hospitalslist = new string[count, 2];
-
- XmlNodeList xhkid = readDoc.GetElementsByTagName("hkid");
- XmlNodeList xhos_key = readDoc.GetElementsByTagName("hos_key");
- for (int i= 0; i <count; i++)
- {
- hospitalslist[i, 0] = xhkid[i].InnerText;
- hospitalslist[i, 1] = xhos_key[i].InnerText;
- }
- for (int i = 0; i < hospitalslist.GetLength(0); i++)
- {
- cmbhusers.Items.Add(new { Text = hospitalslist[i, 1], Key=Convert.ToInt16(hospitalslist[i, 0]) });
- }
- cmbhusers.DisplayMember = "Text";
- cmbhusers.ValueMember = "Key";
- }
- }
- catch (Exception e1)
- {
- MessageBox.Show(e1.Message);
- }
- }