2012-01-06 83 views
1

行,所以我至今這段代碼:添加一個文本行和鏈接按鈕到GridViewRow

  for (int i = 0; i < fajlovi.Length ; i++) 
     { 
      string filename = fajlovi[i]; 
      string link = Server.MapPath("~/upload" + "//" + Page.User.Identity.Name) + fajlovi[i]; 
      LinkButton button = new LinkButton(); 
      button.Text = "Download"; 
      button.PostBackUrl = link; 
      GridViewRow row = new GridViewRow(i, i, DataControlRowType.DataRow, DataControlRowState.Normal); 



     } 

現在我需要的是字符串的文件名與LinkBut​​ton按鈕添加到列在GridView 。我知道我需要創建一個GridViewRow,然後將該行添加到GridView,但我不知道如何將元素添加到行中。

任何人都知道如何使用它?

回答

1

的元素必須被添加到TableCell的,這又必須被添加到GridViewRow:

 // Filename 
     string filename = "..."; 
     Label lbl_filename = new Label(); 
     lbl_filename.Text = filename; 
     // ... 

     // Button 
     LinkButton button = new LinkButton(); 
     button.Text = "Download"; 
     // ... 

     GridViewRow row = new GridViewRow(i, i, DataControlRowType.DataRow, DataControlRowState.Normal); 
     TableCell cell = new TableCell(); 
     cell.ColumnSpan = some_columnspan; 
     cell.HorizontalAlign = HorizontalAlign.Left; 
     cell.Controls.Add(lbl_filename); // add control 
     cell.Controls.Add(button); // add control 
     row.Cells.Add(cell);