i have to bind json data to a repeater i have found one method. i am able to bind the first level of json data. i am unable to bind the second level of json data repeater inside the repeater. here is my json input
{"apiAvailableBuses": [{"droppingPoints":null,"availableSeats":40,"partialCancellationAllowed":false," arrivalTime":"01:00 AM","cancellationPolicy":" [{\"cutoffTime\":\"1\",\"refundInPercentage\":\"10\"},{\"cutoffTime\":\"2\",\"refundInPercentage\":\"50\"},{\"cutoffTime\":\"4\",\"refundInPercentage\":\"90\"}]","boardingPoints":[{"time":"07:40PM","location":"K.P.H.B,Beside R.S Brothers","id":"2238"}],"operatorName":"Apple I Bus","departureTime":"8:00 PM","mTicketAllowed":false,"idProofRequired":false,"serviceId":"6686","fare":"1000","busType":"Hi-Tech A/c","routeScheduleId":"6686","commPCT":9.0,"operatorId":203,"inventoryType":0}, { "droppingPoints":null,"availableSeats":41,"partialCancellationAllowed":false,"arrivalTime":"06:00 AM","cancellationPolicy":"[{\"cutoffTime\":\"1\",\"refundInPercentage\":\"10\"},{\"cutoffTime\":\"2\",\"refundInPercentage\":\"50\"},{\"cutoffTime\":\"4\",\"refundInPercentage\":\"90\"}]","boardingPoints":[{"time":"08:00PM","location":"Punjagutta,","id":"2241"}],"operatorName":"Royalcoach Travels","departureTime":"8:00 PM","mTicketAllowed":false,"idProofRequired":false,"serviceId":"6736","fare":"800","busType":"VOLVO","routeScheduleId":"6736","commPCT":9.0,"operatorId":243,"inventoryType":0}
code:
private void BindItemsInCart(List<apiAvailableBuses> ListOfSelectedProducts) { // The the LIST as the DataSource this.rptItemsInCart.DataSource = ListOfSelectedProducts; // Then bind the repeater // The public properties become the columns of your repeater this.rptItemsInCart.DataBind(); } public void getavailablebuses() { string url = string.Format(HttpContext.Current.Server.MapPath("files/getavailablebuses.json")); using (WebClient client = new WebClient()) { string json = client.DownloadString(url); var result = JsonConvert.DeserializeObject<RootObject>(json); string mm = JObject.Parse(json).SelectToken("apiAvailableBuses").ToString(); // var boardingpoint = JObject.Parse(mm).SelectToken("boardingPoints").ToString(); var Availablebuses = JObject.Parse(json).SelectToken("apiAvailableBuses").ToString(); DataTable dt = (DataTable)JsonConvert.DeserializeObject(Availablebuses, (typeof(DataTable))); BindItemsInCart(result.apiAvailableBuses); } public class apiresult { public string message { get; set; } public string success { get; set; } } public class RootObject { public apiresult apiStatus; public List<apiAvailableBuses> apiAvailableBuses{ get; set; } // public string apiAvailableBuses { get; set; } } public class apiAvailableBuses { public string serviceId { get; set; } public string fare { get; set; } public string busType { get; set; } public string departureTime { get; set; } public string operatorName { get; set; } public string cancellationPolicy { get; set; } public List<boardingpoints> boardingpoints { get; set; } public string droppingPoints { get; set; } public string inventoryType { get; set; } public string routeScheduleId { get; set; } public int availableSeats { get; set; } public string arrivalTime { get; set; } public Boolean idProofRequired { get; set; } public Boolean partialCancellationAllowed { get; set; } public int operatorId { get; set; } public double commPCT { get; set; } public string mTicketAllowed { get; set; } } public class boardingpoints { public string location { get; set; } public string id { get; set; } public string time { get; set; } } public class cancellationPolicy { public string cutoffTime { get; set; } public string refundInPercentage { get; set; } }
design view
<asp:Repeater ID="rptItemsInCart" runat="server"> <HeaderTemplate> <table> <thead> <tr> <th>Product Name</th> <th>Product Description</th> <th>Product Price</th> </tr> </thead> <tbody> </HeaderTemplate> <ItemTemplate> <tr> <td> <%# Eval("serviceId") %></td> <td><%# Eval("fare")%></td> <td><%# Eval("busType")%></td> </tr> </ItemTemplate> <ItemTemplate> <%--<td><%# Eval("boardingPoints.location") %></td>--%> </ItemTemplate> <FooterTemplate> </tbody> </table> </FooterTemplate> </asp:Repeater>
here i am able to bind the data to the repeater i want to bind the boardingpoints data to the dropdownlist or another repeater inside that repeater how to do that please help me i am sleepless from so many days. Thank You in advance