Beispiel #1
0
 public static void FillCombo(this System.Web.UI.WebControls.DropDownList ddl, DropDownName dname, string Condition = "")
 {
     try
     {
         List <clsDropDown>   ddllist = new List <clsDropDown>();
         System.Net.WebClient client  = new System.Net.WebClient();
         client.Headers.Add("content-type", "application/json");//set your header here, you can add multiple headers
         string arr = client.DownloadString(string.Format("{0}api/DropDownData/{1}?&param1={2}", HttpContext.Current.Session["WebApiUrl"].ToString(), dname.ToString(), Condition));
         JavaScriptSerializer serializer = new JavaScriptSerializer();
         ddllist            = serializer.Deserialize <List <clsDropDown> >(arr);
         ddl.DataSource     = ddllist;
         ddl.DataTextField  = "DisplayField";
         ddl.DataValueField = "ValueField";
         ddl.DataBind();
         ddl.Items.Insert(0, new ListItem("--Select--", System.Convert.ToString(0)));
     }
     catch (Exception ex)
     { }
 }
 public static void FillCombo(this System.Web.UI.WebControls.DropDownList ddl, DropDownName dname, string Condition = "")
 {
     try
     {
         List <clsDropDown> ddllist = new List <clsDropDown>();
         using (var client = new HttpClient())
         {
             //client.BaseAddress = new Uri(ConfigurationManager.AppSettings["WebApiUrl"].ToString());
             client.BaseAddress = new Uri(System.Web.HttpContext.Current.Session["WebApiUrl"].ToString());
             client.DefaultRequestHeaders.Accept.Clear();
             client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
             HttpResponseMessage response = client.GetAsync(string.Format("api/DropDownData/{0}?&param1={1}", dname.ToString(), Condition)).Result;
             //response.Content.ReadAsStringAsync().Result
             if (response.IsSuccessStatusCode && !string.IsNullOrEmpty(response.Content.ReadAsStringAsync().Result))
             {
                 System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                 ddllist = serializer.Deserialize <List <clsDropDown> >(response.Content.ReadAsStringAsync().Result);
             }
         }
         ddl.DataSource     = ddllist;
         ddl.DataTextField  = "DisplayField";
         ddl.DataValueField = "ValueField";
         ddl.DataBind();
         ddl.Items.Insert(0, new ListItem("--Select--", System.Convert.ToString(0)));
     }
     catch (Exception ex)
     { }
 }