[Asp.Net+C#]Datagrid使用技巧一(怎样灵活控制表头)

摘要:
今天,当使用Excel作为数据时,当使用DataGrid时,头必须是两行,这是以前从未使用过的,这使得我很难找到表,而且我不想在客户端上使用表。我觉得可读性太差了。研究了一段时间后,我终于找到了一个解决方案,这是先发的。由于时间关系,它不会被整理出来。privatevoidDatagrid1_ItemCreated{ListItemTypeitemtype=e.Item.ItemType;//获取当前创建行intj=0的类别;如果//执行到标头时,{DataGridItemtrnew=newDataGridItem;for{stringstrValue=Datagrid1。列[i]。页眉文本;如果{string[]strArr=strValue.Split(',');trnew.Cells[j].Text=strArr[1];trnew.Cells[j].ColumnSpan=3;trnew.caells[j]。Width=Unit.Pixel;trnew.coells[j.Height=Unit.PPixel;e.Item.Cells[i].Text=strArr[0];j=j+1;}否则{if(Datagrid1.Columns[i].HeaderText!
今天在工作做到处数据为Excel时,在用到DataGrid时,要求表头为两行 ,以前没用过,把我难到了,又不想用用客户端的Table,觉得可读性太差,研究了一会,终于找到了解决方法,先发上来,由于时间关系,就不整理了。呵呵。

private void Datagrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {
   ListItemType itemtype=e.Item.ItemType; //获得当前创建行的类别
   int j=0;
   if(itemtype==ListItemType.Header)//当执行到表头是执行
   {
    DataGridItem trnew=new DataGridItem(0,0,ListItemType.Header);
    for(int i=0;i<Datagrid1.Columns.Count;i++){
     string strValue=Datagrid1.Columns[i].HeaderText;
     if(strValue.Substring(0,2).Equals("A卷"))
     {
      string[] strArr=strValue.Split(',');
      trnew.Cells.Add(new TableCell());
      trnew.Cells[j].Text=strArr[1];
      trnew.Cells[j].ColumnSpan=3;
      trnew.Cells[j].Width=Unit.Pixel(180);
      trnew.Cells[j].Height=Unit.Pixel(22);
      e.Item.Cells[i].Text=strArr[0];
      j=j+1;
     }
     else{
      if(Datagrid1.Columns[i].HeaderText!="B卷"&&Datagrid1.Columns[i].HeaderText!="综合")
      {
       trnew.Cells.Add(new TableCell());
       trnew.Cells[j].Text=e.Item.Cells[i].Text;
       trnew.Cells[j].RowSpan=2;
       j=j+1;
      }
     }
    }
    j=0;
    for(int i=0;i<Datagrid1.Columns.Count;i++)
    {
     if(Datagrid1.Columns[i].HeaderText!="B卷"&&Datagrid1.Columns[i].HeaderText!="综合"&&Datagrid1.Columns[i].HeaderText.Substring(0,2)!="A卷")
     {
      e.Item.Cells.RemoveAt(j);
     }
     else{
      j=j+1;
     }
    }
    Datagrid1.Controls[0].Controls.AddAt(0,trnew);
   }  
  }

免责声明:文章转载自《[Asp.Net+C#]Datagrid使用技巧一(怎样灵活控制表头)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇ElasticSearch索引与搜索SQL SERVER性能分析死锁检测数据库阻塞语句&amp;lt;转&amp;gt;下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

为 ItemsControl 类型的控件提供行号,mvvm模式 绑定集合

从网络上看到的两种方式,一种是,在 codebehind 里为 控件写事件,下面是将集合绑定到 DataGrid 控件: private void DataGridSoftware_LoadingRow(object sender, DataGridRowEventArgs e) { e.Row.Header = e.Row.GetIndex()...

JQuery Easy Ui dataGrid 数据表格

http://www.cnblogs.com/cnjava/archive/2013/01/21/2869876.html 数据表格 - DataGrid 内容 概况 使用方法 数据表格属性 数据列属性 编辑 数据视图 事件 方法 继承$.fn.panel.defaults,使用$.fn.datagrid.defaults重载默认值。. 数据表格显...

Wince下sqlce数据库开发(一)

对于Wince下的sqlce数据库虽然很多人在用,但在我查找资料时,却发现资料是多么的匮乏,在此对自己这几天的了解做个简单介绍,希望对大家能有所帮助! 本文的最后附有所使用到的sqlce在wince下的安装文件,wince截屏工具及本示例代码的下载地址。 1.创建wince项目: 注:wince项目的创建需要在VS2008或者VS2005下 图1 创建“智...

easyui 只刷新当前页面的数据 datagrid reload 方法

$('#refreshbtn').click(function() { $("#t_auclot").datagrid("reload",serializeForm($('#mysearch'))); }); <a class="easyui-linkbutton">刷新</a> easyui dat...

VB6.0操作SQL Server——增删改查

http://www.cnblogs.com/Miss-Lin/archive/2012/08/13/2635848.html一、数据录入通过VB向SQL Server数据库中录入数据,可以使用数据绑定控件录入数据与使用SQL语句录入 1.利用数据绑定控件录入数据 使用数据绑定控件录入数据可以运行较少的代码,实现向数据库中录入数据,数据绑定后,由于数据...

EasyUI的后台界面

EasyUI的后台界面搭建及极致重构 〇、前言 要了解一个东西长什么样,至少得让我们能看到,才能提出针对性的见解。所以,为了言之有物,而不是凭空漫谈,我们先从UI说起,后台管理页面的UI我们将使用应用比较普遍的easyui框架。 以前在用easyui的时候,每个页面都得从0做起,或者不厌其烦地由以前的页面通过“复制-粘贴”的方式来修改,久页久之,就会造成页...