Q:

Using a repeater with a JSON string column

I have a SQL Server stored proc that returns a list of products. I'm using a repeater to display the data in my webpage. This all works fine and the rows are returned nicely. However, for each product I want to get a list of features, so for example:
ProductID, Name, Features
1, T-Shirt, "Blue, Long sleeved, 100% cotton"
2, Jeans, "Blue, Denim, Stonewashed"
Ideally, I want to make a single database call to my proc to return all the products and their features in one go. So, I'm thinking that I need the proc to return three columns (ProductID, ProductName, Features) with the features column being a JSON array.
I am very new to asp.net and even newer to JSON. I'm using c# and in the HTML page, I've been able to get the ProductName and ProductID aspects working nicely. I want it to look like this (the ul tag section is the features):
<div class="card-description"><%# Eval("ProductName") %><br><br>
  <ul>
    <li>Lightweight textured fabric</li> 
    <li>Rounded v-neckline</li> 
    <li>100% cotton</li>
  </ul><br><br>
  Product code: <strong><%# Eval("ProductID") %></strong>
</div>

My question then, is (a) is this the best way to do it, and (b) how do I deserialize the JSON on a row by row basis?
Am I approaching this the wrong way?

A:

Well, I wouldn't have gone towards pushing the JSON data to a databound element. There could be many scenarios to achieve it and that depends how you are managing your records and how are they being processed. I will assume that you have two tables named Products and Features respectively with this schema: Products (Id, Name) and Features(Id, FeatureDescription, ProductId)
So, I would simply suggest you to query your data like this:
SELECT Name AS ProductName, STUFF((SELECT ', ' + FeatureDescription FROM Features WHERE Features.ProductId = Products.Id FOR XML PATH('')), 1, 2, '') AS ProductFeatures FROM Products

And then you could evaluate and bind the returned DataField (ProductFeatures) to any of your HTML tag in the repeater where you want to display it.
If you want to customize the records, you can either use nested Repeater control and when the first repeater triggers ItemDataBound event you can bound the second repeater inside of it. Or you can process the returned CSV response using a Static method like below:
Markup:
<div><%# GetFeaturesHtml(Eval("ProductFeatures"))%></div>

CS:
public static string GetFeaturesHtml(object o)
{
    if(o == null || DBNull.Value.Equals(o))
    {
       return "";
    }
    var splittedFeatures= o.ToString().Split(',');
    var sb = new StringBuilder("<ul>");
    foreach(string feature in splittedFeatures)
    {
        sb.Append(string.Format("<li>{0}</li>", feature));
    }
    sb.Append("</ul>");
    return sb.ToString();
}

And there other ways too, but this would be the simpler and efficient way to do it. Hope this helps.
PS: The code shared is not tested, and it may need some love.

