关闭

重画dataGrid表头的方法

882人阅读 评论(0) 收藏 举报

如果要调用此函数,必须在html中,<asp:datagrid>中添加如下代码:OnItemCreate="myGrid_itemCreat"

如:<asp:datagrid OnItemCreated="myGrid_itemCreat">

 #region 调整表头的宽度 myGrid_itemCreat()
  public void myGrid_itemCreat(object sender,System.Web.UI.WebControls.DataGridItemEventArgs e)
  {
   if(e.Item.ItemType==ListItemType.Header)
   {
    TableCellCollection tc=e.Item.Cells;
    tc.Clear();

    #region 前面列的处理
    tc.Add(new TableHeaderCell());
    tc[0].Text="xxxx";
    tc[0].ColumnSpan=1;
    tc[0].RowSpan = 2;
    tc[0].Wrap=false;

    tc.Add(new TableHeaderCell());
    tc[1].Text="xxxx";
    tc[1].ColumnSpan=2;
    tc[1].RowSpan = 1;
    tc[1].Wrap=false;

    tc.Add(new TableHeaderCell());
    tc[2].Text="xxxx";
    tc[2].ColumnSpan=2;
    tc[2].RowSpan =1;
    tc[2].Wrap=false;

    tc.Add(new TableHeaderCell());
    tc[3].Text="xxxx";
    tc[3].ColumnSpan=2;
    tc[3].RowSpan = 1;
    tc[3].Wrap=false;

    tc.Add(new TableHeaderCell());
    tc[4].Text="xxxx";
    tc[4].ColumnSpan=2;
    tc[4].RowSpan = 1;
    tc[4].Wrap=false;

    tc.Add(new TableHeaderCell());
    tc[5].Text="xxxx";
    tc[5].ColumnSpan=2;
    tc[5].RowSpan = 1;
    tc[5].Wrap=false;

    tc.Add(new TableHeaderCell());
    tc[6].Text="xxxx";
    tc[6].ColumnSpan=2;
    tc[6].RowSpan = 1;
    tc[6].Wrap=false;

    tc.Add(new TableHeaderCell());
    tc[7].Text="xxxx";
    tc[7].ColumnSpan=2;
    tc[7].RowSpan = 1;
    tc[7].Wrap=false;
    #endregion
 
    #region 关键处理
    tc.Add(new TableHeaderCell());
    tc[8].ColumnSpan=2;
    tc[8].RowSpan = 1;
   
    tc[8].Text="<font color='#ffffff'>xxxx</font></tr>";
    tc[8].Text+="<tr><td align=center rowspan='1' colspan='1' bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td>";
    tc[8].Text+="<td align=center colspan='1' rowspan='1' valign=middle bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td>";
    tc[8].Text+="<td align=center rowspan='1' colspan='1' valign=middle bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td>";
    tc[8].Text+="<td align=center colspan='1' rowspan='1' valign=middle bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td>";
    tc[8].Text+="<td align=center rowspan='1' colspan='1' valign=middle bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td>";
    tc[8].Text+="<td align=center colspan='1' rowspan='1' valign=middle bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td>";
    tc[8].Text+="<td align=center rowspan='1' colspan='1' valign=middle bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td>";
    tc[8].Text+="<td align=center colspan='1' rowspan='1' valign=middle bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td>";
    tc[8].Text+="<td align=center rowspan='1' colspan='1' valign=middle bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td>";
    tc[8].Text+="<td align=center colspan='1' rowspan='1' valign=middle bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td>";
    tc[8].Text+="<td align=center rowspan='1' colspan='1' valign=middle bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td>";
    tc[8].Text+="<td align=center colspan='1' rowspan='1' valign=middle bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td>";
    tc[8].Text+="<td align=center rowspan='1' colspan='1' valign=middle bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td>";
    tc[8].Text+="<td align=center colspan='1' rowspan='1' valign=middle bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td>";
    tc[8].Text+="<td align=center rowspan='1' colspan='1' valign=middle bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td>";
    tc[8].Text+="<td align=center colspan='1' rowspan='1' valign=middle bgcolor='#337FB2' nowrap><font color='#ffffff'>xxxx</font></td></tr>";
 
    #endregion
   }
  }
  #endregion

dataGrid的表头,其实就是与table的画法别无二致...


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2289824次
    • 积分:26165
    • 等级:
    • 排名:第229名
    • 原创:1篇
    • 转载:1662篇
    • 译文:0篇
    • 评论:98条
    最新评论