• 修改DataGrid表頭


    DataGrid在ItemDataBound之前我們可以通過DataGrid的ItemCreated事件對表頭進行修改。以達到顯示多層信息的效果
    效果圖請查看附件;表頭總共有三行上面兩行是新添加進去的
    例如:
    private void dglist_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
            {
                try
                {
                    ListItemType lit = e.Item.ItemType;
                    if (ListItemType.Header == lit)
                    {
                        e.Item.SetRenderMethodDelegate(new RenderMethod(NewRenderMethod));
                    }
                }
                catch (Exception ex)
                {
                    this.ExecJavaScript("alert('" + ex.Message + "');");
                }
            }
     private void NewRenderMethod(HtmlTextWriter writer, Control ctl)
            {
                try
                {
                    TableCell cell;
                    for (int i = 0; i < 9; i++)
                    {
                        cell = (TableCell)ctl.Controls[i];
                        cell.Attributes.Add("rowspan", "3");
                        cell.RenderControl(writer);
                    }
                    writer.Write("<td colspan=\"5\" align=\"center\">申請人信息</td>");
                    writer.Write("<td colspan=\"4\" align=\"center\">使用人信息</td>");
                    cell = (TableCell)ctl.Controls[18];
                    cell.Attributes.Add("rowspan", "3");
                    cell.RenderControl(writer);
                    writer.Write("<td colspan=\"6\" align=\"center\">經辦人信息</td>");
                    writer.Write("</tr>\n");
                    this.dglist.HeaderStyle.AddAttributesToRender(writer);
                    writer.RenderBeginTag("tr");
                    for (int i = 9; i < 14; i++)
                    {
                        cell = (TableCell)ctl.Controls[i];
                        cell.Attributes.Add("rowspan", "2");
                        cell.RenderControl(writer);
                    }
                    writer.Write("<td colspan=\"2\" align=\"center\">集團員工</td>");
                    writer.Write("<td colspan=\"2\" align=\"center\">非集團員工</td>");
                    for (int i = 19; i < 25; i++)
                    {
                        cell = (TableCell)ctl.Controls[i];
                        cell.Attributes.Add("rowspan", "2");
                        cell.RenderControl(writer);
                    }
                    writer.Write("</tr>\n");
                    this.dglist.HeaderStyle.AddAttributesToRender(writer);
                    writer.RenderBeginTag("tr");
                    for (int i = 14; i < 18; i++)
                    {
                        cell = (TableCell)ctl.Controls[i];
                        cell.RenderControl(writer);
                    }
                    writer.Write("</tr>\n");
                }
                catch
                {
                }
            }
     
  • 相关阅读:
    python中几种数据类型常用的方法
    WSGI
    从开学到初赛的一些个人总结
    CSP-S2020 浙江 游记
    CF1416D Graph and Queries
    单次期望 O(1) 的RMQ
    P3177 [HAOI2015]树上染色
    CF835F Roads in the Kingdom/P1399 [NOI2013]快餐店
    P4381 [IOI2008]Island
    P5655 基础数论函数练习题
  • 原文地址:https://www.cnblogs.com/tianxiang2046/p/1368754.html
Copyright © 2020-2023  润新知