Home > DeveloperSection > Forums > Split() function isn't giving output
john rob

Total Post:108

Points:756
Posted on    August-21-2014 12:57 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 632  View(s)
Rate this:

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?



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-21-2014 1:15 AM

Hi John, 
try this :

<ul>

  <asp:Repeater id="lblListItemIngredients" runat="server">

    <ItemTemplate>

      <li><%# Container.DataItem %></li>

    </ItemTemplate>

  </asp:Repeater>

</ul>

You don't have to create a list for a data source, an array works just fine:

string str = dataSet.Tables[0].Rows[0]["Ingredients"].ToString();

string[] split = str.Split(',');

lblListItemIngredients.DataSource = split;

lblListItemIngredients.DataBind();


Don't want to miss updates? Please click the below button!

Follow MindStick