Click here to Skip to main content
15,896,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i am a beginner programmer. I have a aspx page and i have a mysql query that counts the amount of entries in the table in database. For each entry in the database i need to have a label and a textbox added to the page. Does anyone know how to do this? Any help will be much appreciated.
Posted

Best suited for you[^]

And importantly, see this[^] also.
 
Share this answer
 
Comments
Jαved 11-Jul-12 2:36am    
+5 good links.
you can see this
 
Share this answer
 
You can use Place Holder to create Controls at Runtime according to the Data into your database.

Use PlaceHolder...

like :
string s1 = "your query ";
SqlDataAdapter ad1 = new SqlDataAdapter(s1,con);
DataSet ds1 = new DataSet();
ad1.Fill(ds1);

if (ds1.Tables[0].Rows.Count != 0)
{
    for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
    {
        Label l = new Label(); // one label created at Runtime
        Label lbl = new Label(); // second label created at runtime
        l.ID = "l" + i.ToString(); // give ID to the first Label
        l.ForeColor = System.Drawing.Color.Orange;
        lbl.ID = "lbl" + i.ToString(); // give ID to the Second Label

        l.Text = ds1.Tables[0].Rows[i][0].ToString(); // set text to the first label
        lbl.Text = ds1.Tables[0].Rows[i][1].ToString(); // set text to the second label
        PlaceHolder1.Controls.Add(l); // add control to the Placeholder
        PlaceHolder1.Controls.Add(new LiteralControl("<br />")); // use for break one line
        PlaceHolder1.Controls.Add(lbl); // add control to the placeholder
        PlaceHolder1.Controls.Add(new LiteralControl("<br />"));
    }

}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900