I have a few code lines like this,
public void rt_changed(object sender, AjaxControlToolkit.RatingEventArgs e)
{
//Label l = sender as Label;
foreach (DataListItem li in datalist.Items)
{
Label l = li.FindControl("nl") as Label;
}
Label3.Text = l.ToString(); // l values is not getting
}
Here the variable l is null. I know it's happening because the declaration of l has been made inside the scope of the foreach. I don't know how to call the variable with a value in globally.
Anonymous User
14-Nov-2014You just need to move the declaration of the l variable outside of the loop to make it available. You can declare (tell what it is) in a different place than where you assign it a value.
Please note that l will only get assigned to the last value in the datalist collection, which probably isn't exactly what you want.