Hi body, i found your Quiestion in Stack Overflow.
c# - Using variable in label name [
^]
I see this top link.
in your code you must put in object from label. like this below. and this solution is worked for me in Window Form Application. may be worked for you in aspx page.
void Button1Click(object sender, EventArgs e)
{
var test = 1;
var labels = Controls.Find("label" + test, true);
if (labels.Length > 0)
{
var label = (Label) labels[0];
label.Text = "Some text goes here...";
}
}
and that's Done . you have access on it!!! Labels[0]
your code must be like this.
for(int i=1; i<5; i++)
{
var labels = Page.FindControl("lblColName" + i);
if (labels.Length > 0)
{
var mylabel = (Label) labels[0];
mylabel.Text = "Excellent!" + i;
}
}
i hope this worked for you. please tell me the result of this !! :)) tnx man