Hi
How to display data returned by Api in repeater/gridview
C#
{
"kind": "youtube#videoCategoryListResponse",
"etag": "fIIv2-q7-AkaOeJf0LPrlnu-0As",
"items": [
{
"kind": "youtube#videoCategory",
"etag": "grPOPYEUUZN3ltuDUGEWlrTR90U",
"id": "1",
"snippet": {
"title": "Film & Animation",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "Q0xgUf8BFM8rW3W0R9wNq809xyA",
"id": "2",
"snippet": {
"title": "Autos & Vehicles",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "qnpwjh5QlWM5hrnZCvHisquztC4",
"id": "10",
"snippet": {
"title": "Music",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "HyFIixS5BZaoBdkQdLzPdoXWipg",
"id": "15",
"snippet": {
"title": "Pets & Animals",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "PNU8SwXhjsF90fmkilVohofOi4I",
"id": "17",
"snippet": {
"title": "Sports",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "5kFljz9YJ4lEgSfVwHWi5kTAwAs",
"id": "18",
"snippet": {
"title": "Short Movies",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "ANnLQyzEA_9m3bMyJXMhKTCOiyg",
"id": "19",
"snippet": {
"title": "Travel & Events",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "0Hh6gbZ9zWjnV3sfdZjKB5LQr6E",
"id": "20",
"snippet": {
"title": "Gaming",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "q8Cp4pUfCD8Fuh8VJ_yl5cBCVNw",
"id": "21",
"snippet": {
"title": "Videoblogging",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "cHDaaqPDZsJT1FPr1-MwtyIhR28",
"id": "22",
"snippet": {
"title": "People & Blogs",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "3Uz364xBbKY50a2s0XQlv-gXJds",
"id": "23",
"snippet": {
"title": "Comedy",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "0srcLUqQzO7-NGLF7QnhdVzJQmY",
"id": "24",
"snippet": {
"title": "Entertainment",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "bQlQMjmYX7DyFkX4w3kT0osJyIc",
"id": "25",
"snippet": {
"title": "News & Politics",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "Y06N41HP_WlZmeREZvkGF0HW5pg",
"id": "26",
"snippet": {
"title": "Howto & Style",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "yBaNkLx4sX9NcDmFgAmxQcV4Y30",
"id": "27",
"snippet": {
"title": "Education",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "Mxy3A-SkmnR7MhJDZRS4DuAIbQA",
"id": "28",
"snippet": {
"title": "Science & Technology",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "4pIHL_AdN2kO7btAGAP1TvPucNk",
"id": "30",
"snippet": {
"title": "Movies",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "Iqol1myDwh2AuOnxjtn2AfYwJTU",
"id": "31",
"snippet": {
"title": "Anime/Animation",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "tzhBKCBcYWZLPai5INY4id91ss8",
"id": "32",
"snippet": {
"title": "Action/Adventure",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "ii8nBGYpKyl6FyzP3cmBCevdrbs",
"id": "33",
"snippet": {
"title": "Classics",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "Y0u9UAQCCGp60G11Arac5Mp46z4",
"id": "34",
"snippet": {
"title": "Comedy",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "_YDnyT205AMuX8etu8loOiQjbD4",
"id": "35",
"snippet": {
"title": "Documentary",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "eAl2b-uqIGRDgnlMa0EsGZjXmWg",
"id": "36",
"snippet": {
"title": "Drama",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "HDAW2HFOt3SqeDI00X-eL7OELfY",
"id": "37",
"snippet": {
"title": "Family",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "QHiWh3niw5hjDrim85M8IGF45eE",
"id": "38",
"snippet": {
"title": "Foreign",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "ztKcSS7GpH9uEyZk9nQCdNujvGg",
"id": "39",
"snippet": {
"title": "Horror",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "Ids1sm8QFeSo_cDlpcUNrnEBYWA",
"id": "40",
"snippet": {
"title": "Sci-Fi/Fantasy",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "qhfgS7MzzZHIy_UZ1dlawl1GbnY",
"id": "41",
"snippet": {
"title": "Thriller",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "TxVSfGoUyT7CJ7h7ebjg4vhIt6g",
"id": "42",
"snippet": {
"title": "Shorts",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "o9w6eNqzjHPnNbKDujnQd8pklXM",
"id": "43",
"snippet": {
"title": "Shows",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "mLdyKd0VgXKDI6GevTLBAcvRlIU",
"id": "44",
"snippet": {
"title": "Trailers",
"assignable": false,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
}
]
}Thanks

Vishal JoshiRank #377 · 6.7K reputationPosted Jan 12, 2023, 6:20 AM EST
Hello,
Directly bind JSON data to repeater control is not possible. you can convert it to Datatable and bind it. Please check below code for the task.
public partial class PageClass : BasePage{ protected void Page_Load(object sender, EventArgs e) { Root _objRoot = JsonConvert.DeserializeObject(yourJSONDataString); Repeater1.DataSource = GetDataTableFromObjects(_objRoot.root); Repeater1.DataBind(); } public DataTable ToDataTable(List items) { DataTable dataTable = new DataTable(typeof(T).Name); //Get all the properties PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo prop in Props) { //Setting column names as Property names dataTable.Columns.Add(prop.Name); } foreach (T item in items) { var values = new object[Props.Length]; for (int i = 0; i (myJsonResponse); public class Item { public string kind { get; set; } public string etag { get; set; } public string id { get; set; } public Snippet snippet { get; set; } } public class Root { public string kind { get; set; } public string etag { get; set; } public List items { get; set; } } public class Snippet { public string title { get; set; } public bool assignable { get; set; } public string channelId { get; set; } }Thank you
Vikas PanwarRank #1,447 · 1.1K reputationPosted Jan 12, 2023, 8:18 AM EST
Convert your json into dataset and bind gridview with dataset.
public static DataSet ConvertJsonStringToDataSet(string jsonString) { try { XmlDocument xd = new XmlDocument(); jsonString = "{ \"rootNode\": {" + jsonString.Trim().TrimStart('{').TrimEnd('}') + "} }"; xd = (XmlDocument)JsonConvert.DeserializeXmlNode(jsonString); DataSet ds = new DataSet(); ds.ReadXml(new XmlNodeReader(xd)); return ds; } catch (Exception ex) { throw new ArgumentException(ex.Message); } }