![](/img/trans.png)
[英]C# Asp.Net changing DataSource for GridView using DropDownList
[英]Dynamically changing GridView row (ASP.NET,C#)
我有一個GridView,它需要顯示GridView的x列數,或者僅顯示一列(單元格),它將擴展以占據整個行。 通過檢查一列是否為空白來確定要顯示的內容-如果該列為空白,則顯示其他單元格;否則,僅顯示該單元格。
我將如何去做呢? 我正在使用SqlDataSource選擇GridView的內容,但我願意更改它以采用更具編程性的方法。
謝謝
我不確定我是否理解正確,但是如果您願意,可以自己構建Table 。 然后,您可以精確控制要包括的列(和數據)。
Table table = new Table();
table.GridLines = GridLines.None;
table.CellPadding = 3;
table.CellSpacing = 0;
// add a header
TableHeaderRow header = new TableHeaderRow();
foreach (string header in new string[] { "column1", "column2" }) {
TableCell cell = new TableCell();
cell.Text = header;
header.Cells.Add(cell);
}
// add data
foreach (var rowd in data) {
TableRow row = new TableRow();
foreach (string columnData in new string[] { rowd.Column1, rowd.Column2 }){
TableCell cell = new TableCell();
cell.Text = columnData;
row.Cells.Add(cell);
}
table.Rows.Add(row);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.