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();
                Response.Write("<p>");                          
                --------------------------
                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

Recommended Answers

All 2 Replies

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
Next

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)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.