DataGrid 自定义分页导航

本文围绕DataGrid控件展开,介绍了自定义分页导航的实现方法,使分页呈现特定样式;还阐述了在DataGrid等控件中实现自动编号的方式,即添加模版列;此外,详细说明了在DataGrid中创建复杂表头的两种方法,包括用table实现和动态生成双层、三层表头。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

DataGrid 自定义分页导航


效果:  

让DataGrid自己的分页实现这样的效果
[1][2][3][4][5][6]

  

private void grid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {
   if(e.Item.ItemType==ListItemType.Pager)
   {    
    foreach (Control c in e.Item.Cells[0].Controls)
    {
     if (c is Label)  //
当前页数
     {
        Label lblpage=(Label)c;
//      lblpage.ForeColor= System.Drawing.ColorTranslator.FromHtml("#e 78a 29"); //#e 78a 29 ,#FF0000     
//      lblpage.Font.Bold=true;
        lblpage.Text="[<font color=#e 78a 29><b>"+lblpage.Text+"</b></font>]";     
      //((Label)c).ForeColor = System.Drawing.Color.Green;      
//      break;
     }
     if(c is LinkButton) //
链接的其他页数
     {      
         LinkButton linkButton = (LinkButton)c;       
         linkButton.Text = "[" + linkButton.Text+"]";
     }
    }    
   }
  }

 

 

DataGrid等控件中的自动编号:

添加一个模版列:

<asp:TemplateColumn HeaderText="No.">
    
<ItemStyle HorizontalAlign="Center"></ItemStyle>
    
<ItemTemplate>
        
<asp:Label runat="server" Text= <%# dgCustomize.CurrentPageIndex*dgCustomize.PageSize+dgCustomize.Items.Count+1 %> >
        
</asp:Label>
    
</ItemTemplate>
</asp:TemplateColumn>

 

 

DataGrid中创建复杂表头

方法一:用table实现

  <form id="Form1" method="post" runat="server">
   <TABLE id="Table1" runat="server" cellSpacing="1" cellPadding="2" width="580" border="1"
    bgcolor="#cc6633" bordercolor="#cc9966" style="FONT-SIZE: 9pt ;BORDER-BOTTOM:0px">
    <TR align="center">
     <TD colspan="2" width="380" style="HEIGHT: 21px"></TD>
     <TD width="200" colspan="2" style="HEIGHT: 21px"></TD>
    </TR>
    <TR align="center">
     <TD width="200" bgcolor="#66cc99"><FONT face="
宋体"></FONT></TD>
     <TD width="180" bgcolor="white"><FONT face="
宋体"></FONT></TD>
     <TD width="160" bgcolor="#99cccc"></TD>
     <TD width="40" bgcolor="#009999"></TD>
    </TR>
   </TABLE>
   <asp:DataGrid id="DataGrid1" width="580px" AlternatingItemStyle-BackColor="#6699ff" CellPadding="2"
    CellSpacing="1" BorderWidth="1" BorderColor="#cc9966" Font-Size=" 9pt " runat="server" ShowHeader="False"
    AutoGenerateColumns="False">
    <Columns>
     <asp:BoundColumn DataField="Title">
      <ItemStyle Width="200px"></ItemStyle>
     </asp:BoundColumn>
     <asp:BoundColumn DataField="CreateDate">
      <ItemStyle Width="180px"></ItemStyle>
     </asp:BoundColumn>
     <asp:BoundColumn DataField="pid">
      <ItemStyle Width="160px"></ItemStyle>
     </asp:BoundColumn>
     <asp:BoundColumn DataField="HitCount">
      <ItemStyle Width="40px"></ItemStyle>
     </asp:BoundColumn>
    </Columns>
   </asp:DataGrid>   
  </form> 

窗体顶端

 

 

 

 

 

 

窗体底端

方法二:动态生成表头

生成双层表头:
  private void grid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {

   if (e.Item.ItemType == ListItemType.Header)
   {
//    e.Item.Cells[0].ColumnSpan = 1;//
这是第一列的跨列数
    StringBuilder strtext=new StringBuilder();
    strtext.Append("//</td>");
    strtext.Append("<td colspan=4>
生活照明</td>");
    strtext.Append("<td colspan=2>
一般照明</td>");
    strtext.Append("<td colspan=2>
工付业</td>");
    strtext.Append("<td colspan=2>
农业</td>");
    strtext.Append("<td colspan=2>
合计</td>");
    strtext.Append("</tr>");
    strtext.Append("<tr>");
    strtext.Append("<td>" + e.Item.Cells[0].Text);               
    e.Item.Cells[0].Text =strtext.ToString();

   }

}

整个表头内容:<tr><td>  e.Item.Cells[0].Text =的内容  </td></tr>

加起来就是表头的样式。

生活照明

一般照明

工付业

农业

合计

 

 

 

 

 

 

 

 

 

 

 

 

 

生成三层表头:

if (e.Item.ItemType == ListItemType.Header)
   {    
    StringBuilder strtext=new StringBuilder();
    strtext.Append("</td>");
    strtext.Append("<td colspan= 6>
当月</td>");
    strtext.Append("</tr>");

 

    strtext.Append("<tr>"); 
    strtext.Append("<td colspan=2>
居民</td>");
    strtext.Append("<td colspan=2>
一般</td>");
    strtext.Append("<td colspan=2>
工付业</td>");
    strtext.Append("</tr>");

 

    strtext.Append("<tr>");
    strtext.Append("<td>" + e.Item.Cells[0].Text);               
    e.Item.Cells[0].Text =strtext.ToString();
   }

 

当月

居民

一般

工付业

 

 

 

 

 

 

内容概要:该研究通过在黑龙江省某示范村进行24小时实地测试,比较了燃煤炉具与自动/手动进料生物质炉具的污染物排放特征。结果显示,生物质炉具相比燃煤炉具显著降低了PM2.5、CO和SO2的排放(自动进料分别降低41.2%、54.3%、40.0%;手动进料降低35.3%、22.1%、20.0%),但NOx排放未降低甚至有所增加。研究还发现,经济性和便利性是影响生物质炉具推广的重要因素。该研究不仅提供了实际排放数据支持,还通过Python代码详细复现了排放特征比较、减排效果计算和结果可视化,进一步探讨了燃料性质、动态排放特征、碳平衡计算以及政策建议。 适合人群:从事环境科学研究的学者、政府环保部门工作人员、能源政策制定者、关注农村能源转型的社会人士。 使用场景及目标:①评估生物质炉具在农村地区的推广潜力;②为政策制定者提供科学依据,优化补贴政策;③帮助研究人员深入了解生物质炉具的排放特征和技术改进方向;④为企业研发更高效的生物质炉具提供参考。 其他说明:该研究通过大量数据分析和模拟,揭示了生物质炉具在实际应用中的优点和挑战,特别是NOx排放增加的问题。研究还提出了多项具体的技术改进方向和政策建议,如优化进料方式、提高热效率、建设本地颗粒厂等,为生物质炉具的广泛推广提供了可行路径。此外,研究还开发了一个智能政策建议生成系统,可以根据不同地区的特征定制化生成政策建议,为农村能源转型提供了有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值