Dynamically Generate Table and Update Database

Jul 14, 2008 at 6:02 PM

I have dynamically generated table, with loaded data from db.

 

* I assign  3 columns,  1 for description, 2 for current value , 3 for New value....

* then I want to update 2nd column's Current value by 3rd column's value (this values user will enter) 

table look like this

------------------------------------- 

description         Value 

userID                    205

UserName                Prasan

------------                    -------

------------                    -------

 

rows can be increase thats y  I thought to generate table dynamically               

 -------------------------------------

( Table in database only have  2 columns (1st & 2nd Columns) can use 1st column for reference when update table ) 

i already done this.........

 Table tbl   = new Table();

  Panel1.Controls.Add(tbl);

  foreach(DataRow dataRow in DS.Tables[0].Rows)
            {
                tr          = new TableRow();

                for (int Column = 0; Column < tblCols; Column++)
                {
                    tc      = new TableCell();
                    txtBox  = new TextBox();
                    lbl     = new Label();

                   if (Column == 0)
                    {                     
                        tc.Controls.Add(lbl);                       
                        lbl.ID             = "lbl"+Row;
                        lbl.Text         = dataRow[0].ToString();    //  description for current values   
             
                    }
                    else
                    {
                     
                        if (Column == 1)
                        {
                            txtBox.ID                   = "txtCurrent" + Row;
                            txtBox.Text               = dataRow[1].ToString();
                            txtBox.ReadOnly      = true;                               // read only Current values from db           
                        }

                        else if(Column == 2)
                        {                        
                                txtBox.ID   = "txtNew" + Row;                 //    New Value for replace with Current Value
                        }

                        tc.Controls.Add(txtBox);

                    }
                
                    tr.Cells.Add(tc);     // Add the TableCell to the TableRow
                }
              
                tbl.Rows.Add(tr);  // Add the TableRow to the Table
                Row++;
            }
      
          
            ViewState["dynamictable"]           = true;     // This parameter helps determine in the LoadViewState event,

 

 

Does anyone know a better way for handling that?