Oussema Oz February 2016

Dynamicaly add buttons to asp table cell without deleting the cells text

i have an asp.table where all the cells contains text and the following function to add buttons to the cells

  Button btnactiv = new Button();
                    btnactiv.ID = y.ToString();
                    btnactiv.Text = "Dept " + dr_depts["code_dept"].ToString() + "(" + nbr + " )";
                    cell.Controls.Add(btnactiv);

the buttons are added and it works fine but the text of cells gets deleted after i add the buttons how can i add butoons and keep the text please ?

Answers


Suman Pathak February 2016

first dynamically create a table cell and then add your text and button to it:

 TableCell commentCell = new TableCell();
 Label lblComment = new Label();
 lblComment.Text = "Text to remain in the cell."
 commentCell.Controls.Add(lblComment);
 Button btnactiv = new Button();
 btnactiv.ID = y.ToString();
 btnactiv.Text = "Dept " + dr_depts["code_dept"].ToString() + "(" + nbr + " )";
 commentCell.Controls.Add(btnactiv);

Post Status

Asked in February 2016
Viewed 2,793 times
Voted 4
Answered 1 times

Search




Leave an answer