2014-02-19 69 views
0

我有它返回我的代碼使用來填充表List<string>的方法:ASP.NET:插入表格單元編程

string[] siteNames; 
siteNames = client.GetListSiteElementNames(); 

foreach (string siteName in siteNames) 
{ 
    TableCell tempCell = new TableCell(); 
    tempCell.Text = siteName; 
    this.sitesTableRow.Cells.Add(tempCell); 
} 

這就將細胞上單行,所以細胞呈現水平地穿過屏幕(我想怎麼樣),但是因爲他們是20個左右,所以他們離開頁面意味着您需要滾動查看其餘部分。

有沒有什麼辦法可以做到這一點,以便細胞在窗口邊緣切斷並進入新的生產線?

感謝

+0

http://stackoverflow.com/questions/11250501/wrap-long-html-tables-to-next-line 這可以幫助你 –

回答

0
string[] siteNames; 
siteNames = client.GetListSiteElementNames(); 

foreach (string siteName in siteNames) 
{ 
    TableCell tempCell = new TableCell(); 
    /* Here add a new line */ 
    tempCell.Text = siteName + Environment.NewLine; 
    this.sitesTableRow.Cells.Add(tempCell); 

} 

編輯:我的錯誤。我誤解了你的要求。

+0

這是行不通的,因爲這將只是追加一個新行至底部每個細胞,它不會強制細胞包裹。 – Nunners

+0

這裏沒有任何反應;結果與之前一樣 – Phil

0

要做到這一點,你需要一定的分界點後添加一個新行(即某些列數)

在下面的例子中我使用了一個截止5:

string[] siteNames; 
siteNames = client.GetListSiteElementNames(); 

// Number of cells on each row 
int cutOffPoint = 5; 
int currentNum = 1; 

foreach (string siteName in siteNames) { 
    TableCell tempCell = new TableCell(); 
    tempCell.Text = siteName; 

    if (currentNum > cutOffPoint) { 
     currentNum = 1; 

     // Code to add new row to table 
    }  

    this.sitesTableRow.Cells.Add(tempCell); 

    currentNum++; 
} 

因爲我不確定this對象所指的是什麼或sitesTableRow我不能包含添加行的代碼,但想法是在6個單元格之後,您將重置currentNum變量並添加一個新行,並將這些單元格添加到這個新行中。

+0

我以前曾經考慮過這種方式,但我希望窗口大小調整時單元格可以換行。這可能是最簡單的方法。想知道是否有任何CSS樣式你可以做。 – Phil

+0

@PhilipLoffler爲此,您可以使用除表以外的其他東西,您可以創建一個浮動DIV元素的HTML字符串,這將使您可以將它們包裝在重新調整大小。 – Nunners

+0

@Phil查看[this](http://stackoverflow.com/questions/11250501/wrap-long-html-tables-to-next-line)爲例。 – Nunners