Whats wrong in the code..? It isn’t working!!
Actually I want to split the entries from one of the field of database.. The items in it are separated by commas..
Here is what I am doing.
string str = dataSet.Tables[0].Rows[0]["Ingredients"].ToString();
string[] split = str.Split(',');
IList<string> lblListItemIngredients = new List<string>();
foreach (string item in split)
{
lblListItemIngredients.Add(item);
}
and in my aspx page,
<ul>
<li>
<asp:label id="lblListItemIngredients" runat="server></asp:Label>
</li>
</ul>
But the output isn’t coming, but in debugging mode, i can see the string is splitting.. Whats wrong?
You have to get the data in the list to the control somehow. That doesn’t happen magically just because you give a variable the same name as the id of the control.
Actually, you should use a different name for the variable, otherwise it will shadow the property that has been added to the page object.
If you want to make a HTML list it’s not enough to put a label in one list item, that won’t create one list item for each string. You can use a repeater:
You don’t have to create a list for a data source, an array works just fine: