DataGrid中创建复杂表头方法,欢迎多交流点方法

GOOGLE下发现有许多创建双行跨列的DATAGRID表头的文章.
大部分是利用在Pager创建时将Pager列去掉而和Header一起形成两行表头(注Pager会在Header前先建立)
如[http://dev.csdn.net/develop/article/18/18971.shtm
自己也认真学习了一天,发现DATAGRID实际上还是table,

所以我就只用DATALIST实现就可以搞贴

再加个分页函数,完全OK.

<asp:datalist id="MainDataList" runat="server" BorderWidth="0px" CellPadding="0" BorderStyle="None"
                                                GridLines
="Horizontal" RepeatLayout="Flow" RepeatDirection="Horizontal">
                                                
<HeaderTemplate>
                                                    
<TABLE style="BORDER-RIGHT: #cccccc 1px; BORDER-TOP: #cccccc 1px; BORDER-LEFT: #cccccc 1px; BORDER-BOTTOM: #cccccc 1px; BORDER-COLLAPSE: collapse"
                                                        borderColor
="#cccccc" cellSpacing="0" cellPadding="0" rules="all" border="1">
                                                        
<TR class="red_99" style="FONT-WEIGHT: bold; COLOR: white; HEIGHT: 30px; BACKGROUND-COLOR: #3399cc"
                                                            align
="center">
                                                            
<TD width="100" rowSpan="2">
                                                                
<DIV align="center" class="white_99">小区</DIV>
                                                            
</TD>
                                                            
<TD width="100" rowSpan="2">
                                                                
<DIV align="center" class="white_99">大楼</DIV>
                                                            
</TD>
                                                            
<TD width="100" rowSpan="2">
                                                                
<DIV align="center" class="white_99">房号</DIV>
                                                            
</TD>
                                                            
<TD width="70" rowSpan="2">
                                                                
<DIV align="center" class="white_99">底数</DIV>
                                                            
</TD>
                                                            
<TD colSpan="3" height="22">
                                                                
<DIV align="center" class="white_99">本月应收</DIV>
                                                            
</TD>
                                                            
<TD colSpan="2" height="22">
                                                                
<DIV align="center" class="white_99">实收</DIV>
                                                            
</TD>
                                                            
<TD colSpan="2" height="22">
                                                                
<DIV align="center" class="white_99">累欠</DIV>
                                                            
</TD>
                                                        
</TR>
                                                        
<TR class="red_99" style="FONT-WEIGHT: bold; COLOR: white; HEIGHT: 30px; BACKGROUND-COLOR: #3399cc"
                                                            vAlign
="bottom" align="center" class="white_99">
                                                            
<TD width="60" height="21">
                                                                
<DIV align="center" class="white_99">抄表</DIV>
                                                            
</TD>
                                                            
<TD width="55" height="21">
                                                                
<DIV align="center" class="white_99">用量</DIV>
                                                            
</TD>
                                                            
<TD width="70" height="21">
                                                                
<DIV align="center" class="white_99">金额</DIV>
                                                            
</TD>
                                                            
<TD width="60" height="21">
                                                                
<DIV align="center" class="white_99">数量</DIV>
                                                            
</TD>
                                                            
<TD width="60" height="21">
                                                                
<DIV align="center" class="white_99">金额</DIV>
                                                            
</TD>
                                                            
<TD width="55" height="21">
                                                                
<DIV align="center" class="white_99">数量</DIV>
                                                            
</TD>
                                                            
<TD width="70" height="21">
                                                                
<DIV align="center" class="white_99">金额</DIV>
                                                            
</TD>
                                                        
</TR>
                                                
</HeaderTemplate>
                                                
<FooterTemplate>
                        
</table>
                        
</FooterTemplate>
                        
<ItemStyle BorderWidth="0px" BorderStyle="None" BackColor="#FFFFFF"></ItemStyle>
                        
<ItemTemplate>
                            
<tr bgcolor="<%# strBgcolor%>">
                                
<td height="20"><div align="left"><%# IncludedSqlClass.GetSectionNameFromKez_no(DataBinder.Eval(Container, "DataItem.kez_no").ToString()) %></div>
                                
</td>
                                
<td height="20"><div align="left"><%# IncludedSqlClass.GetBuildNameFromKez_no(DataBinder.Eval(Container, "DataItem.kez_no").ToString()) %></div>
                                
</td>
                                
<td height="20"><div align="left"><%# DataBinder.Eval(Container, "DataItem.chargecode").ToString() %></div>
                                
</td>
                                
<td height="20"><div align="right"><%# DataBinder.Eval(Container, "DataItem.ultimoread").ToString() %></div>
                                
</td>
                                
<td height="20"><div align="right"><%# DataBinder.Eval(Container, "DataItem.thismonthread").ToString() %></div>
                                
</td>
                                
<td height="20"><div align="right"><%# DataBinder.Eval(Container, "DataItem.thisuse").ToString() %></div>
                                
</td>
                                
<td height="20"><div align="right"><%# DataBinder.Eval(Container, "DataItem.thisreceivable","{0:C}").ToString() %></div>
                                
</td>
                                
<td height="20"><div align="right"><%# DataBinder.Eval(Container, "DataItem.realuse").ToString() %></div>
                                
</td>
                                
<td height="20"><div align="right"><%# DataBinder.Eval(Container, "DataItem.realmoney","{0:C}").ToString() %></div>
                                
</td>
                                
<td height="20"><div align="right"><%# DataBinder.Eval(Container, "DataItem.spareuse").ToString() %></div>
                                
</td>
                                
<td height="20"><div align="right"><%# DataBinder.Eval(Container, "DataItem.sparemoney","{0:C}").ToString() %></div>
                                
</td>
                            
</tr>
                        
</ItemTemplate>
                        
</asp:datalist>
private void MainDataList_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
        
{
            
if(strBgcolor=="#ffffff")
            
{
                strBgcolor
="#f0f8f3";
            }

            
else
            
{
                strBgcolor
="#ffffff";
            }

        }

posted on 2005-10-14 14:11  Blackie  阅读(2567)  评论(6编辑  收藏  举报

导航