-1

My question i asked for "Randomly" adding controls in spefic Table Cells. e.g.

if i call funtion CreateTable() , it should create tables with vary number of rows and columns, and then for example if i want a text box in Cell(0,1), a dropdown in cell(2,1) then again a text area control in Cell(5,1) etc etc.( u getting my point, i am not putting one type of control), how can i code that.The control state should be saved in the table.And whenever i open particylar webform it show shos all the control which i have created before

1 Answers1

0
private void CreateTable(short noOfRows)
{
    PlaceHolder p1 = new PlaceHolder();

    Table table1 = new Table();
    table1.BorderWidth = 1;
    table1.BorderStyle = BorderStyle.Solid;

    TableRow[] rows = new TableRow[noOfRows];

    for (int i = 0; i < rows.Length; i++)
    {
        rows[i] = new TableRow();
    }

    table1.Rows.AddRange(rows);

    TextBox t1 = new TextBox();
    t1.Text = "Hello";
    t1.EnableViewState = true;

    TextBox t2 = new TextBox();
    t2.Text = "World";
    t2.EnableViewState = true;

    Button btnOk = new Button();
    btnOk.EnableViewState = true;
    btnOk.Text = "OK";

    Button btnCancel = new Button();
    btnCancel.EnableViewState = true;
    btnCancel.Text = "Cancel";


    TableCell cell1=new TableCell();
    TableCell cell2 = new TableCell();
    TableCell cell3 = new TableCell();
    TableCell cell4 = new TableCell();

    cell1.Controls.Add(t1);
    cell2.Controls.Add(t2);
    cell3.Controls.Add(btnOk);
    cell4.Controls.Add(btnCancel);

    table1.Rows[0].Cells.AddAt(0, cell1);
    table1.Rows[0].Cells.AddAt(1, cell2);
    table1.Rows[1].Cells.AddAt(0, cell3);
    table1.Rows[1].Cells.AddAt(1, cell4);

    p1.Controls.Add(table1); 
    form1.Controls.Add(p1);        

}
Shyju
  • 203
  • 1
  • 5
  • Thanks but my requirement is that there are different control for each webform .When i select one control it should be shown in the other webform. Control may be any like textbox,checkbox,dropdown only label name will change.And it should be shown on the web form. – user2524673 Apr 06 '15 at 08:04
  • Something like master form which have controls because each webform have different controls and label name and we have to create new form each time our requirement changes.And it takes two days.So,i want to do something like maste control form – user2524673 Apr 06 '15 at 08:08
  • So you are creating dynamic web forms with controls created on demand, am I correct? – Shyju Apr 06 '15 at 08:23
  • There is Admin Side who added the information about the project.And Also project configuration for where Admin selected the control and control name for like Name.Another modlule is User when he opened the particular project he/she must she all the control and control name on the flow.(that may be textbox,radiobutton,dropdown whichever admin have configured for that).What should I do whether to save the control and their value to database or what pls help – user2524673 Apr 09 '15 at 11:51
  • Check whether you are looking for something like this, http://stackoverflow.com/questions/792278/dynamic-form-generation-in-asp-net – Shyju Apr 10 '15 at 08:16