合并实现DataGrid多表头 (转自:http://singlepine.cnblogs.com/articles/282990.html)

本文介绍了一种在ASP.NET Web应用程序中使用DataGrid控件时,通过自定义渲染方法实现复杂表格头合并的方法。该方法利用了Hashtable来跟踪跨行单元格的位置,并通过覆盖默认的渲染过程来达到美观且灵活的布局效果。
<HTML>
    
<HEAD>
        
<title>MergeHeader</title>
        
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        
<meta name="CODE_LANGUAGE" Content="C#">
        
<meta name="vs_defaultClientScript" content="JavaScript">
        
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    
</HEAD>
    
<body MS_POSITIONING="GridLayout">
        
<form id="Form1" method="post" runat="server">
            
<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server"
                BorderColor
="Tan" BorderWidth="1px" BackColor="LightGoldenrodYellow" CellPadding="1" ForeColor="Black"
                CellSpacing
="1">
                
<FooterStyle BackColor="Tan"></FooterStyle>
                
<SelectedItemStyle ForeColor="GhostWhite" BackColor="DarkSlateBlue"></SelectedItemStyle>
                
<AlternatingItemStyle BackColor="PaleGoldenrod"></AlternatingItemStyle>
                
<HeaderStyle Font-Bold="True" BackColor="Tan"></HeaderStyle>
                
<PagerStyle HorizontalAlign="Center" ForeColor="DarkSlateBlue" BackColor="PaleGoldenrod"></PagerStyle>
            
</asp:datagrid>
        
</form>
    
</body>
</HTML>

public class MergeHeader : System.Web.UI.Page
    
{
        
private DataGrid m_dgDatagridToDecorate = null;
        
private ArrayList m_arrHeaderCells = null;
        
protected System.Web.UI.WebControls.DataGrid DataGrid1;        
        
private Hashtable m_htblRowspanIndex = new Hashtable();

        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
if(!this.IsPostBack)
            
{
                MergeGrid();
            }

        }


        
AddMergeHeader

        
property        

        
DatagridToDecorate_ItemCreated        

        
NewRenderMethod

        
GetData

        
MergeGrid        

        
Web Form Designer generated code        
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值