I am using ASP.net 2.0 with c#.I fetch the data from database using sqldatareader.when i fetch data for one label control it works fine. what i need is, in my web form i have 6 lables named as lbl1,lbl2,lbl3,lbl4......
so i would like to incremement the lable id ,
i did as i given below,

while (dr.Read())
            for (int i = 1; i <= 2; i++)
            {  lbl1.Text = dr["name"].ToString();
                lbl2.Text = dr["design"].ToString();
                Label lbl = new Label();
                lbl.ID = "lbl" + i.ToString();
            }     }   

but i don't know how to set the data for the particular id.
so pls help me this.

thanks in advance

Edited by Nick Evan: Fixed formatting

9 Years
Discussion Span
Last Post by Jihad

No you can't create a control array in asp.net like vb 6 or windows application.
you have to create every control on page be drag and drop thus embeded in HTML format.

For i = 0 To Controls.Count - 1

str = ctype(page.FindControl("lbl") , Label).Text)
If Left(str, 3) = "lbl" Then

End If


Try to use literal. Literal is a control that inserts an html code in its place, that html code can be anything you want, even labels. You can se the text of the literal at certain event like on page loading or drop down list index change, it as simple as this

your_literal.Text = String.Format("<input type=""label"" name=""MyLabel""  id=""MyLabel{0}"" value=""{0}"" style=""background-color: #DE0221"" ", i)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.