filling comboboxes from webapi IQueryable method

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Text;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace DXWebApplication2
{
public partial class Default: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
RegisterAsyncTask(new PageAsyncTask(test));

}
}


private async Task<bool> test()
{
try
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:52793/");
client.DefaultRequestHeaders.Accept.Clear();

//GET Method 
HttpResponseMessage responsez = await client.GetAsync("api/Porini_tbSiparisUst");
if (responsez.IsSuccessStatusCode)
{
var st = await responsez.Content.ReadAsStringAsync();

var XYZ = JsonConvert.DeserializeObject(st);

var jt = ((Newtonsoft.Json.Linq.JToken)XYZ)[0];

//Eğer Kolon İsilerini Bilmiyorsak
foreach (JObject item in (Newtonsoft.Json.Linq.JArray)XYZ)
{
int counter = 0;
foreach (var pair in item)
{

if(++counter == 8)
{
this.DropDownList1.Items.Add(pair.Value.ToString());
}
}
counter = 0;

}

//Eğer Kolon İsimlerini Biliyorsak
foreach (JObject item in (Newtonsoft.Json.Linq.JArray)XYZ)
{

foreach (var pair in item)
{

if (pair.Key.Equals("TIPKODU"))
{
this.DropDownList2.Items.Add(pair.Value.ToString());
}
}


}



var aaaaa = 1;


}
else
{
Console.WriteLine("Internal server Error");
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
return false;
}

return true;
}


}
}

Yorumlar