hi i am getting the single row json data depending on selection of dropdownlist using web api , i want to bind that data to textboxes.
here is my code. 'insurance_master' is my table
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string url = "http://localhost:50435/api/Insurance_Master/" + DropDownList1.SelectedValue;
WebRequest req = WebRequest.Create(url);
req.Method = "GET";
// req.Headers.Add("key");
req.ContentType = "application/json; charset=utf-8";
WebResponse resp = req.GetResponse();
Stream stream = resp.GetResponseStream();
StreamReader re = new StreamReader(stream);
String json = re.ReadToEnd();
json = "{\"insurancedetails\":" + json + "}";
wrapper w = (wrapper)new JavaScriptSerializer().Deserialize(json, typeof(wrapper));
}
public class wrapper
{
public List insurancedetails { get; set; }
}
Help me,
Thanks in advance
Anupam SinghPosted Apr 18, 2014, 4:23 AM
that was'nt what I was asking. any way.
Let me try to help you ..
in json how do you handle it that may create problem.
You have to create new Type for handling it
suppose you json data have name,id
then create a class
eg.
class Person
{
public string Name {get;set;}
public int Id {get;set;}
}
then use "Newtonsoft.Json" download it form http://www.nuget.org/packages/Newtonsoft.Json/6.0.1
next put data into it
var jsondata = (Person)Newtonsoft.Json.JsonConvert.DeserializeObject(MyObjectDictionary["Person"], typeof(Person));
Now you can access it by using jsondata .Name and jsondata .Id
try this hope it will help.
Nidadavole ChowdaryPosted Apr 18, 2014, 1:40 AM
DropDownList1.DataSource = w.insurancedetails;
DropDownList1.DataBind();
i have created my model using entityframework mvc4
i created the insurance_master controller. i successfully bind the data to dropdownlist.
i created the dropdownlist as follows
i want to get details of customer on clicking policy number in dropdownlist.
i populate the dropdown in pageload.
Anupam SinghPosted Apr 18, 2014, 1:08 AM