惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
T
Tailwind CSS Blog
T
The Blog of Author Tim Ferriss
U
Unit 42
B
Blog
N
Netflix TechBlog - Medium
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
O
OpenAI News
M
MIT News - Artificial intelligence
D
DataBreaches.Net
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
LINUX DO - 热门话题
C
CERT Recently Published Vulnerability Notes
V
Visual Studio Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
Vercel News
Vercel News
T
Tenable Blog
Security Latest
Security Latest
C
Check Point Blog
云风的 BLOG
云风的 BLOG
PCI Perspectives
PCI Perspectives
月光博客
月光博客
TaoSecurity Blog
TaoSecurity Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Project Zero
Project Zero
雷峰网
雷峰网
IT之家
IT之家
H
Hacker News: Front Page
Microsoft Security Blog
Microsoft Security Blog
B
Blog RSS Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Last Week in AI
Last Week in AI
G
Google Developers Blog
Forbes - Security
Forbes - Security
The Register - Security
The Register - Security
Cyberwarzone
Cyberwarzone
小众软件
小众软件
Martin Fowler
Martin Fowler
K
Kaspersky official blog
P
Proofpoint News Feed
T
Threatpost
Google Online Security Blog
Google Online Security Blog
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - lrary

JavaScript经典技巧 - lrary - 博客园 动态添加ASP.NET控件并绑定处理事件一例 - lrary - 博客园 脚本收藏 - lrary - 博客园 一些sql语句的详细解释[转] 特殊的DataGrid的绑定 - lrary - 博客园 纯脚本搞掂DataGrid表表头不动,表身滚动。(转摘) - lrary - 博客园 检验密码强度的JS类 - lrary - 博客园 数据库设计规范 V2.0 SQL语句特---殊统计(1) DataGrid 多行 AJAX 在.net的应用 sql怎么使用外连接 Asp.NET程序中常用的三十三种代码 检测含有中文字符串的实际长度 根据区位得到汉字拼音首字母(c#) 认识ASP.NET配置文件Web.config Asp.net(C#)实现验证码功能 给Repeater、Datalist和Datagrid增加自动编号列 查找和统计页面上控件
DataGrid怎么产生一个分类的题头
lrary · 2006-05-09 · via 博客园 - lrary

 我在写PowerDataGrid想到要提供一个查询(有关PowerDataGrid的详细信息参考CSDN论坛中的讨论帖,源码可以在www.foxhis.com/powermjtest/sharepowerdatagrid.rar下载),该查询的构想是这样的:我的这个控件可以通过指定一个SQL语句来显示该语句的内容(其他的功能不叙述了,这不是重点),那么我可以封装一组UI到这个控件里面来实现查询的功能,问题出来了,这个查询通常情况下应该在DataGrid的上面也就是查询结果的上面,我要怎么才能保留原来的题头同时再添加一个题头呢(双题头)?
    问题出来了,改如何解决呢?想了好多办法都不行,如果要将Header重画,那么还要处理排序是前后台的交互问题,那么只能再保留原来Header不动的基础上添加新的Header。无意中发现在分页的时候可以有几种分页显示的方法,在分页面板里面有一个选现可以选择分页的位置,可以选择上下型,在选择这个类型的时候DataGrid在原来的Header上面又多了一行,我们今天就利用这一行来完成我们的任务,今天我们不产生查询的UI而是产生一个分类的题头,我们使用测试数据库Northwind中的Employees来显示数据,首先我们要做的是绑定数据绑定代码如下:
SqlConnection con = new SqlConnection("server=localhost;database=Northwind;uid=sa;pwd=;");
         SqlDataAdapter da = new SqlDataAdapter("SELECT LastName+' '+FirstName as name, BirthDate, Country, Title, HireDate FROM Employees",con);
         DataTable dt = new DataTable();
         da.Fill(dt);
         this.DataGrid1.DataSource = dt;
         this.DataGrid1.DataBind();
}
    接着我们在ItemCreated里面添加适当的代码来完成我们的任务,在PowerDataGrid该事件处理函数里面已经添加了创建一个自定义分页的UI!如果你在PowerDataGrid里面添加需要判断两个(上下)Pager的位置,我们可以使用一个全局变量来判断。
    定义一个全局变量 private int m_CreatePageTimes = 0;
    然后我们为该事件处理函数添加如下代码:
private int m_CreatePageTimes  = 0;
private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {
         ListItemType elemType = e.Item.ItemType;
         if (elemType == ListItemType.Pager) {
            if (m_CreatePageTimes == 0) {
               TableCell cellPerson = (TableCell) e.Item.Controls[0];
               cellPerson.Controls.Clear();
               cellPerson.BackColor = Color.Navy;
               cellPerson.ForeColor = Color.Yellow;
               cellPerson.ColumnSpan = 3;
               cellPerson.HorizontalAlign = HorizontalAlign.Center;
               cellPerson.Controls.Add(new LiteralControl("个人信息"));
 
               TableCell cellJob = new TableCell();
               cellJob.BackColor = Color.Navy;
               cellJob.ForeColor = Color.Yellow;
               cellJob.ColumnSpan = 2;
               cellJob.HorizontalAlign = HorizontalAlign.Center;
               cellJob.Controls.Add(new LiteralControl("工作信息"));
               e.Item.Controls.Add(cellJob);
               m_CreatePageTimes  ++;
            }else if(m_CreatePageTimes ==1){
               // create custom pager UI
            }
         }
    最后是DataGrid的HTML部分的代码如下:
<asp:DataGrid id="DataGrid1" runat="server" AllowPaging="True" AutoGenerateColumns="False" Width="100%"
     PageSize="2">
     <Columns>
      <asp:BoundColumn DataField="name" HeaderText="姓名"></asp:BoundColumn>
      <asp:BoundColumn DataField="BirthDate" HeaderText="生日"></asp:BoundColumn>
      <asp:BoundColumn DataField="Country" HeaderText="国家"></asp:BoundColumn>
      <asp:BoundColumn DataField="Title" HeaderText="头衔"></asp:BoundColumn>
      <asp:BoundColumn DataField="HireDate" HeaderText="雇佣日期"></asp:BoundColumn>
     </Columns>
     <PagerStyle Position="TopAndBottom" Mode="NumericPages"></PagerStyle>
    </asp:DataGrid>
  运行效果如下所示: