how to create an interface automatically of labes/textboxes, based on the structure of my tables in the database;
I would like know if someone has source code, link or some help code to realize this.
in c#
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pankaj Rawat71 reputationPosted Mar 23, 2013, 12:53 AM EDT
Suppose your table name is Contact_List
First in Design Page.
create a Div.
In Code Behind.
here i create a table at runtime.then add table row in it and then create two table cell .
protected void Page_Load(object sender, EventArgs e)
{
If(!IsPostback)
{
DataTable dt_tableField=new DataTable();
using(SqlConnection conn=new SqlConnection(ConfigurationManager.ConnectionString["ApplicationServices"].connectionString))
{
conn.Open();
sqlCommand cmd=conn.CreateCommand();
cmd.CommandText="Select Column_Name from INFORMATION_SCHEMA.COLUMNS where Table_Name='Contact_List' order By Oridinal Position";
SqlDataReader reader_Object=cmd.ExecuteReader();
dt_tableField.load(reader_Object);
conn.close();
}
if(dt_tableField.rows.count>0)
{
Table newtable_Obj=new Table();
TableRow newtablerow_Object;
foreach(DataRow dtrow in dt_tableField.rows)
{
newtablerow_Object=new TableRow();
TableCell newtablecell_Object=new TableCell();
TableCell newtablecell_Object2=new TableCell();
Label labelObject=new Label();
labelObject.ID="lbl"+dtrow[0].tostring();
labelObject.Text=dtrow[o].ToString();
newtablecell_Object.Control.Add(labelObject);
Textbox textboxObject=new Textbox();
textbox.ID="txt"+dtrow[0].ToString();
newtablecell_Object2.Controls.Add(textboxObject);
newtablerow_Object.Cells.Add(newtablecell_Object);
newtablerow_Object.Cells.Add(newtablecell_Object2);
newtable_Obj.Controls.ADd(newtablerow_Object);
}
CreateInterface.Control.Add(newtable_Obj);
}
}
}
Similarly you can create a button and add event to it at runtime.
i hope this will help you.
greg dorian96 reputationPosted Mar 26, 2013, 1:39 PM EDT
thx!!