Hi, I am trying to dynamically generate labels from a datatable. But they are all being displyed in one single line. How can I add a line break between them ? Here's my code. please let me know where I am going wrong?
Dim
lbl1 AsNewLabel() LabelControls.Controls.Add(lbl1)
LabelControls.Controls.Add(lbl1) If
dtab.Rows.Count > 0 Then For
i AsInteger
= 0 To
dtab.Rows.Count - 1 lbl1.Text = dtab.Rows(i)(1) Next
LabelControls.Controls.Add(NewLiteralControl("<br
/>")) EndIf
Dim
lbl1 AsNewLabel() LabelControls.Controls.Add(lbl1)
LabelControls.Controls.Add(lbl1)
It looks like right here you are adding the labels back to back which will but them on the same row.
Try this:
Dim lbl1 As New Label()
LabelControls.Controls.Add(lbl1)
LabelControls.Controls.Add(New LiteralControl("<br />"))
LabelControls.Controls.Add(lbl1)
If dtab.Rows.Count > 0 Then
For i As Integer = 0 To dtab.Rows.Count - 1
lbl1.Text = dtab.Rows(i)(1)
Next
End If
Dim
lbl1 AsNewLabel() LabelControls.Controls.Add(lbl1)
LabelControls.Controls.Add(lbl1) If
dtab.Rows.Count > 0 Then For
i AsInteger
= 0 To
dtab.Rows.Count - 1 lbl1.Text = dtab.Rows(i)(1) + "<br/>" Next
LabelControls.Controls.Add(NewLiteralControl("<br
/>")) EndIf
hope this helps...
Cheers!
KK
Please mark as Answer if post helps in resolving your issue
My Site
Dim
lbl1 AsNewLabel() LabelControls.Controls.Add(lbl1)
LabelControls.Controls.Add(lbl1) If
dtab.Rows.Count > 0 Then For
i AsInteger
= 0 To
dtab.Rows.Count - 1 lbl1.Text = dtab.Rows(i)(1) + "<br/>" Next
LabelControls.Controls.Add(NewLiteralControl("<br
/>")) EndIf
hope this helps...
the breaks are showing up but the same column is repeating for the number of rows that are present.
For Eg: isntead of displaying Name, ID, CIty, State, Country
its displaying Name, Name, Name, Name, Name but with line breaks
is appending the labels everytime. So if i have to display 5 labels for the first selection and 7 for the second, so instead of displaying 7 labels on selection 2, I have total of 12 labels displayed.
If i remove the lbl1.text+ dtab.... i can get just one of the labels to display?
snailpace
Member
31 Points
285 Posts
Line breaks between dynamically generated labels
May 02, 2012 02:00 PM|LINK
Hi, I am trying to dynamically generate labels from a datatable. But they are all being displyed in one single line. How can I add a line break between them ? Here's my code. please let me know where I am going wrong?
Dim lbl1 As New Label()
LabelControls.Controls.Add(lbl1)
LabelControls.Controls.Add(lbl1)
If dtab.Rows.Count > 0 Then
For i As Integer = 0 To dtab.Rows.Count - 1
lbl1.Text = dtab.Rows(i)(1)
Next
LabelControls.Controls.Add(New LiteralControl("<br />"))
End If
Thanks
Loganix77
Participant
1351 Points
412 Posts
Re: Line breaks between dynamically generated labels
May 02, 2012 02:10 PM|LINK
It looks like right here you are adding the labels back to back which will but them on the same row.
Try this:
Dim lbl1 As New Label() LabelControls.Controls.Add(lbl1) LabelControls.Controls.Add(New LiteralControl("<br />")) LabelControls.Controls.Add(lbl1) If dtab.Rows.Count > 0 Then For i As Integer = 0 To dtab.Rows.Count - 1 lbl1.Text = dtab.Rows(i)(1) Next End Ifkedarrkulkar...
All-Star
35563 Points
5700 Posts
Re: Line breaks between dynamically generated labels
May 02, 2012 02:13 PM|LINK
try this
Dim lbl1 As New Label()
LabelControls.Controls.Add(lbl1)
LabelControls.Controls.Add(lbl1)
If dtab.Rows.Count > 0 Then
For i As Integer = 0 To dtab.Rows.Count - 1
lbl1.Text = dtab.Rows(i)(1) + "<br/>"
Next
LabelControls.Controls.Add(New LiteralControl("<br />"))
End If
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
rio.jones
Member
246 Points
53 Posts
Re: Line breaks between dynamically generated labels
May 02, 2012 02:13 PM|LINK
check this link this may help you out
http://stackoverflow.com/questions/830304/hw-to-create-line-breaks-between-dynamically-generated-labels-in-a-placeholder
snailpace
Member
31 Points
285 Posts
Re: Line breaks between dynamically generated labels
May 02, 2012 02:21 PM|LINK
i've tried
the breaks are showing up but the same column is repeating for the number of rows that are present.
For Eg: isntead of displaying Name, ID, CIty, State, Country
its displaying Name, Name, Name, Name, Name but with line breaks
thanks
kedarrkulkar...
All-Star
35563 Points
5700 Posts
Re: Line breaks between dynamically generated labels
May 02, 2012 02:27 PM|LINK
it does not have to do with line breaks.... does it worked fine before using my solution?
if u r looking for displaying different column values of same row... then u might want to change this
lbl1.Text = dtab.Rows(i)(1) + "<br/>"
as
lbl1.Text = dtab.Rows(1)(i) + "<br/>"
i.e. display different columns values of first row... is it what u did ealrier?
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
snailpace
Member
31 Points
285 Posts
Re: Line breaks between dynamically generated labels
May 02, 2012 02:32 PM|LINK
thank you for the reply kedarkulkarni.
i am trying to get all values from one column. but different rows.
earlier i was getting the values from the column all in a single row. to break them apart i used the literal control.
the code you sent is breaking the column values, but why is only one value being repeated? I am trying to figure this out.
Any help will be appreciated
thanks
kedarrkulkar...
All-Star
35563 Points
5700 Posts
Re: Line breaks between dynamically generated labels
May 02, 2012 02:42 PM|LINK
does this solve the issue?
lbl1.Text = lbl1.Text + dtab.Rows(i)(1) + "<br/>"
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
snailpace
Member
31 Points
285 Posts
Re: Line breaks between dynamically generated labels
May 02, 2012 02:46 PM|LINK
yes. absolutely!
thanks so much for the help!
snailpace
Member
31 Points
285 Posts
Re: Line breaks between dynamically generated labels
May 03, 2012 02:24 PM|LINK
I'm in a loop again!
This
lbl1.Text = lbl1.Text + dtab.Rows(i)(1) + "<br/>"
is appending the labels everytime. So if i have to display 5 labels for the first selection and 7 for the second, so instead of displaying 7 labels on selection 2, I have total of 12 labels displayed.
If i remove the lbl1.text+ dtab.... i can get just one of the labels to display?
Please help!