다음 이미지에서 "테이블 만들기"버튼을 클릭하면 표시된 테이블이 동적으로 생성됩니다.HOw는 동적으로 생성 된 컨트롤을 처리 할 수 있습니다
나는 textboxes, fileupload, Buttons를 테이블에 동적으로 추가했습니다.
테이블의 "업로드"버튼을 클릭하면 fileupload 컨트롤에서 파일을 업로드하려고하지만 동적으로 생성 된 컨트롤을 처리하는 방법을 알지 못합니다.
은 "표 만들기"버튼의 코드는 다음과 같이 진행됩니다
protected void Button1_Click(object sender, EventArgs e)
{
//Button1.Visible = false;
//Creat the Table and Add it to the Page
Table table = new Table();
table.Caption = "Table1";
table.BackColor = System.Drawing.Color.BurlyWood;
Page.Form.Controls.Add(table);
for (int i = 0; i < 3; i++)
{
TableRow row = new TableRow();
row.BorderStyle = BorderStyle.Ridge;
for (int j = 0; j <= 10; j++)
{
TableCell cell = new TableCell();
cell.BorderWidth = 5;
cell.BorderStyle = BorderStyle.Ridge;
cell.BorderColor = System.Drawing.Color.Azure;
for (j = 0; j <= 0; j++)
{
Label lbl = new Label();
lbl.ID = "lblCCRow" + i + "Col" + j;
lbl.Text = "CC NO. " + i + " ";
lbl.Width = 100;
// Add the control to the TableCell
cell.Controls.Add(lbl);
}
for (j = 1; j <= 1; j++)
{
Label lbl = new Label();
lbl.ID = "lblRow" + i + "Col" + j;
lbl.Width = 100;
lbl.Text = Convert.ToString(DateTime.Now.Day) + "/" + Convert.ToString(DateTime.Now.Month) + "/" + Convert.ToString(DateTime.Now.Year);
// Add the control to the TableCell
cell.Controls.Add(lbl);
}
for (j = 2; j <= 7; j++)
{
TextBox tb = new TextBox();
tb.Width = 100;
tb.ID = "txtBoxRow" + i + "Col" + j;
tb.Text = "";
// Add the control to the TableCell
cell.Controls.Add(tb);
}
for (j = 8; j <= 8; j++)
{
FileUpload fileUp = new FileUpload();
fileUp.ID = "flupRow" + i + "Col" + j;
fileUp.Width = 220;
cell.Controls.Add(fileUp);
}
for (j = 9; j <= 9; j++)
{
Button btnUpld = new Button();
btnUpld.Width = 100;
btnUpld.ID = "btnUpRow" + i + "Col" + j;
btnUpld.Text = "Upload";
cell.Controls.Add(btnUpld);
}
for (j = 10; j <= 10; j++)
{
Label lbl = new Label();
lbl.ID = "lblRow" + i + "Col" + j;
lbl.Text = "[ Status ]";
lbl.Width = 100;
// Add the control to the TableCell
cell.Controls.Add(lbl);
}
row.Cells.Add(cell);
}
// Add the TableRow to the Table
table.Rows.Add(row);
}
//table.Rows.Add(row);
}
thnx의 수레 쉬를 사용하여이 이벤트를 처리하는 기능을 만들 위의 코드를 사용하여 양식에 동적 제어를 추가 한 후 이벤트 핸들러를 추가하고 추가) 매우 도움이되었다 –
환영 Nishant. – SP007