John K John K - 6 months ago 38 Question

How to add labels dynamically to html

I'm getting data into my code behind file in the format of array list. The sproc will return several records depending upon the input parameter value. Now i need to display all these values in HTML as labels dynamically.

For example if i got 2 records, i just need to display those 2 records, if 10 records are returned then display 10 records. I don't want keep 10 static labels to bind all the time. I just looking to place only one label in html and want to use that one to display all the records returned by query. Will it be possible??

Sample code:

//Client side
<asp:Label ID="lblresult" runat="server" CssClass="label" ></asp:Label>

//server side

Dim arraylist as arrayList = //result from sproc
Dim lbltext As String = ""
For Each item In arraylist
Do While item.value = lbltext
Me.lblresult.Text = item.value
lbltext = item.value

Please let me how to solve this? Thanks in advance!


Kinda late for this, but is this what you are looking for?

        For i = 0 To YourArrayList.Count - 1
            lblresult.Text &= YourArrayList(i).ToString & " "

Also this will cause you an error:

        Dim arraylist as arrayList = //result from sproc

arraylist is a reserved keyword. You might want to use another name.