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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pankaj RawatPosted Mar 23, 2013, 4:53 AM
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 dorianPosted Mar 26, 2013, 5:39 PM
thx!!