i have 10 labels on my form.
named label1,label2...........................label10
i want to fill the text in that , simply we do label1.Text="abc";
but i want to fill it through loop , because i have some condition
for (int i = 1; i <= 10; i++)
{
if (ds.Tables["Papers"].Rows[0][i].ToString()!= null)
{
// here i want the label names accroding to the value of i , ex :- if i=1 then here label1.text="abc";
and when i=2 then label2.text="abc";
how can i do this
}
}
Loading

Roei BarPosted Oct 13, 2009, 2:02 AM
Vikas AhlawatPosted Oct 21, 2009, 1:55 PM
but not able to do it how can i perform
Kirtan PatelPosted Oct 13, 2009, 4:35 PM
private void button1_Click(object sender, EventArgs e)
{
int i = 1;
foreach (Control c in this.Controls)
{
if (c is Label)
{
((Label)c).Text = "abc";
}
}
}
Rajeswari nathanPosted Oct 13, 2009, 2:22 AM
Then copy that Lable and past it in the same form. It will created as control array..
Vikas AhlawatPosted Oct 13, 2009, 2:00 AM
Rajeswari nathanPosted Oct 13, 2009, 1:38 AM
so you can fill the lables using their index
Mylable(i).Text = "test" like that..