Reputation: 756
public void rt_changed(object sender, AjaxControlToolkit.RatingEventArgs e)
{
// Declare l, also give it a default value, in the case that datalist is empty.
Label l = null;
foreach (DataListItem li in datalist.Items)
{
l = li.FindControl("nl") as Label;
}
Label3.Text = l.Text; // l values is not getting
}
In this, am getting only last value from my Datalist to Label3. Based on my click am not getting the values in label. What should I change/do in this code ?
Upvotes: 0
Views: 178
Reputation: 223247
The reason you are seeing the last record is that you are not retaining the value of your label in your loop. Better use a StringBuilder
.
public void rt_changed(object sender, AjaxControlToolkit.RatingEventArgs e)
{
StringBuilder sb = new StringBuilder();
// Declare l, also give it a default value, in the case that datalist is empty.
Label l = null;
foreach (DataListItem li in datalist.Items)
{
l = li.FindControl("nl") as Label;
sb.AppendLine(l.Text);
}
Label3.Text = sb.ToString(); // l values is not getting
}
Upvotes: 1