2014-04-23 5 views
1

C#을 통해 행이 추가 된 ASP.NET 테이블이 있는데 C# 코드를 사용하여 셀 안에 ASP 단추를 추가 할 수 있습니까? 나는 주위를 둘러 보았다 그리고 내가 뭘하려고 오전에 관련된 것도/ASP 테이블 셀 안에 ASP 단추 추가

+0

지금 C# 또는 마크 업을 게시 할 수 있습니까? –

+0

리피터 컨트롤을 사용해야합니다 .... – DavidB

+1

'table.Rows [0] .Cells [0] .Controls.Add (새 버튼 {텍스트 = "일부 버튼"});' – Habib

답변

1
public void AddButton() 
    { 

      // Create new row and add it to the table. 
      TableRow tRow = new TableRow(); 
      Table1.Rows.Add(tRow); 
      for (cellCtr = 1; cellCtr <= cellCnt; cellCtr++) { 
      // Create a new cell and add it to the row. 
      TableCell tCell = new TableCell(); 
      tCell.Text = "Row " + rowCtr + ", Cell " + cellCtr; 
      tRow.Cells.Add(tCell); 
      Button bt = new Button(); 
      bt.text = "Click Me"; 
      bt.OnClick += OnClick; 
      tRow.controls.add(bt); 

    void GreetingBtn_Click(Object sender, EventArgs e) 
    { 
     // do whatever you want to do 
    } 
2
Button button=new Button(); 
button.Text="Hello, world!"; 
table.Rows[0].Cells[0].Controls.Add(button); 

버튼을 만들기를 찾을 수 없습니다, 해당 속성을 설정하고 추가 할 컨트롤의 Controls 컬렉션에 추가 한 그것까지. 동적 컨트롤에 대해 ViewState를 유지하거나 ViewState에 수동으로 컨트롤을 추가하려면 Page_Init에서이 작업을 수행해야합니다.