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

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
Jina AI
Jina AI
博客园_首页
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
L
Lohrmann on Cybersecurity
Forbes - Security
Forbes - Security
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
N
News | PayPal Newsroom
S
Security Archives - TechRepublic
量子位
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
C
Cisco Blogs
The Cloudflare Blog
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
Scott Helme
Scott Helme
S
Securelist
Security Latest
Security Latest
爱范儿
爱范儿
TaoSecurity Blog
TaoSecurity Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
I
Intezer
L
LINUX DO - 最新话题
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
美团技术团队
Know Your Adversary
Know Your Adversary
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
PCI Perspectives
PCI Perspectives
月光博客
月光博客
T
Tailwind CSS Blog
Cloudbric
Cloudbric
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
K
Kaspersky official blog
D
DataBreaches.Net
博客园 - 【当耐特】
有赞技术团队
有赞技术团队

博客园 - 流星石

水晶报表中如何改变报表的背景色、显示行数等。 如何动态生成水晶报表(ASP.NET) C编写的SQL Server 数据库连接通用类库 使用Facade模式分析 DreamWeaver MX 2004中 设为首页和加入收藏的实现 DreamWeaver MX 2004制作树状菜单 DreamWeaver MX 2004利用层进行下拉菜单的制作 Grove---------.NET中的ORM实现 .NET下的加密编程 在ASP.NET中写一个数据层基类-----DbObject 在ASP.NET页面中显示年月日和星期的代码实现 在ASP.NET中实现多文件上传 构建简单的Web Service服务 C#中写COM+组件 在ASP.NET 中实现Model-View-Controller 数据库操作源代码 用C#写一个Web自定义日期时间控件 C#.net常用函数和方法集 Together for .net建模入门
asp.net中DataGrid双行跨列表头设计心得
流星石 · 2005-07-16 · via 博客园 - 流星石

一、DataGrid的属性设置
  1. AllowPaging:  true
  2. PageStyle->Position: TopAndBottom
    3. 可选:PageStyle->HorizonAlign: Center(使文本居中显示)
  4. 可选:ItemStyle->HorizonAlign: Center(使文本居中显示)
二、代码部分
  1.首先,使DataGrid绑定数据库中某个表,例如:
 private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   if(!IsPostBack)
   {
    SqlConnection myConn=new SqlConnection("server=localhost;uid=sa;pwd=sa;database=db_test");
    SqlDataAdapter da=new SqlDataAdapter("Select * from 个人",myConn);
    DataSet ds=new DataSet();
    da.Fill(ds,"gr");
    dgGeRen.DataSource=ds.Tables["gr"].DefaultView;
    dgGeRen.DataBind();


   }
  2.为DataGrid添加ItemCreated事件的处理函数、
  3.为了判断DataGrid中的两个(上下)Pager的位置,我们可以使用一个全局变量来判断。
    定义一个全局变量 private int m_CreatePageTimes = 0;
  4.为DataGrid的ItemCreated事件的处理函数添加内容,如下:
  private void dgGeRen_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {
   switch(e.Item.ItemType)
   {
     //case(ListItemType.Pager):
    case ListItemType.Pager:
    {
     if(m_CreatePageTimes == 0)
     {
      DataGridItem row=(DataGridItem)e.Item;
      row.Cells.Clear();
      
      //row.BackColor=Color.Navy;  //背景色
      //row.ForeColor=Color.Red; //前景色
      
      row.HorizontalAlign=HorizontalAlign.Center;//使文本居中显示

      TableCell cell0=new TableCell();
      cell0.RowSpan=2;
      cell0.Controls.Add(new LiteralControl("姓名"));

      TableCell cell1=new TableCell();
      cell1.ColumnSpan=2;   //默认的ColumnSpan值为1
      cell1.Text="住房地址信息";
      
      //也可如此:cell1.Controls.Add(new LiteralControl("住房地址信息"));

      //TableCell cell2=new TableCell();
      //cell2.Controls.Add(new LiteralControl(""));
      TableCell cell2=new TableCell();
      cell2.RowSpan=2;
      cell2.Text="出生日期";

      row.Cells.Add(cell0);
      row.Cells.Add(cell1);
      row.Cells.Add(cell2);
      

      m_CreatePageTimes++;
     }
     break;
    }
    case ListItemType.Header:
    {
     DataGridItem head=(DataGridItem)e.Item;
     head.Cells.Clear();

     //head.VerticalAlign=VerticalAlign.Middle;
     //head.HorizontalAlign=HorizontalAlign.Center;

     //TableCell cell00=new TableCell();
     //cell00.RowSpan=2;
     //cell00.Text="姓名";

     TableCell cell01=new TableCell();
     cell01.Text="楼号";

     TableCell cell02=new TableCell();
     cell02.Text="房号";

     //TableCell cell03=new TableCell();
     //cell03.Text="出生日期";

     //head.Cells.Add(cell00);
     head.Cells.Add(cell01);
     head.Cells.Add(cell02);
     //head.Cells.Add(cell03);
     break;
    }

   }
  
  }