可能因為排版緣故,導致刊登於MSDN上的ASP.NET GridView 範例集中Group Row的部份程式碼有錯誤,
特於此列出正確的程式碼(主要是泛型List的泛型參數問題,由於使用了<,> 符號,可能於排版時漏掉了).
Group Row 程式碼
|
private void PrepareGroup() { int lastSupID = -1; GridViewRow currentRow = null; List<GridViewRow> <gridviewrow></gridviewrow>tempModifyRows = new List<GridViewRow><gridviewrow></gridviewrow>(); foreach (GridViewRow row in GridView1.Rows) { if (row.RowType == DataControlRowType.DataRow) { if (currentRow == null) { currentRow = row; int.TryParse(row.Cells[2].Text, out lastSupID); continue; }
int currSupID = -1; if (int.TryParse(row.Cells[2].Text, out currSupID)) { if (lastSupID != currSupID) { currentRow.Cells[2].Attributes["rowspan"] = (tempModifyRows.Count+1).ToString(); currentRow.Cells[2].Attributes["valign"] = "center"; foreach (GridViewRow row2 in tempModifyRows) row2.Cells.RemoveAt(2); lastSupID = currSupID; tempModifyRows.Clear(); currentRow = row; lastSupID = currSupID; } else tempModifyRows.Add(row); } } }
if (tempModifyRows.Count > 0) { currentRow.Cells[2].Attributes["rowspan"] = (tempModifyRows.Count + 1).ToString(); currentRow.Cells[2].Attributes["valign"] = "center"; foreach (GridViewRow row2 in tempModifyRows) row2.Cells.RemoveAt(2); } }
protected void GridView1_PreRender(object sender, EventArgs e) { PrepareGroup(); }
|
抱歉造成各位讀者的困擾了 ^_^
分享到:
相关推荐
ASP.net GridView双击事件,弹出一个窗口显示详细信息,模式窗口显示详细信息。
ASp.NET GridView 编辑模板ASp.NET GridView 编辑模板
Formatting ASP.NET GridView using jQuery Highlight row on mouseover in GridView using jQuery Set Alternate color for GridView columns using jQuery Change cursor to hand on mouseover in GridView ...
一个漂亮的GridView CSS 模板样式。 测试过,可用。
Asp.net GridView标题列可拖动调整宽度效果实现,实现效果类似于Winform中的ListView控件拖动标题,必变列宽,但界面与listview控件不一样,需要自己改变gridivew样式,具体是根据js插件实现;
ASP.NET GridView表格列宽拖动功能示例,很值得一看!
Asp.net gridview 的样式
asp.net 导出GridView里的数据到Excel中
asp.net GridView导出excel.rar
ASP.NET GridView中两种全选方法.txt
ASP.NET固定GridView表头_SuperTables
【ASP.NET编程知识】ASP.NET GridView中文本内容无法换行(自动换行正常换行).docx
博文《Bootstrap Pagination for ASP.NET GridView》源代码
Display image gallery in ASP.NET GridView Control。
博文《ASP.NET: GridView CRUD using Twitter Bootstrap Modal Popup 》中提及的源代码
附详细使用说明,非常简单,解决问题直接了当。
asp.net GridView自定义控件源码,美化控件。
没分换分了 增删改,分页排序,无代码,导入导出等
asp.net ajax GridView 无刷新
GridView和GridData 行单击弹出详细页面 双击编辑状态更新