zoukankan      html  css  js  c++  java
  • 数据控件头的修改

    前台代码:

    View Code
    1 <asp:GridView ID="GridView1" runat="server" BorderColor="Black" AutoGenerateColumns="False" OnRowCreated="GridView1_RowCreated"
    2 OnRowDataBound="GridView1_RowDataBound">
    3 <Columns>
    4 <asp:BoundField DataField="编号" HeaderText="编号" />
    5 <asp:BoundField DataField="姓名" HeaderText="姓名" />
    6 <asp:BoundField DataField="出生年月" HeaderText="出生年月" />
    7 <asp:BoundField DataField="家庭住址" HeaderText="家庭住址" />
    8 <asp:BoundField DataField="邮政编码" HeaderText="邮政编码" />
    9 <asp:BoundField DataField="起薪" HeaderText="起薪" />
    10 </Columns>
    11 </asp:GridView>

    后台代码:

    View Code
    1 protected void Page_Load(object sender, EventArgs e)
    2 {
    3 if (!IsPostBack)
    4 {
    5 databind();
    6 }
    7
    8 }
    9 public void databind()
    10 {
    11 SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ToString());
    12 SqlCommand cmd = new SqlCommand();
    13 cmd.Connection = con;
    14 cmd.CommandText = "select * from T_Message";
    15 SqlDataAdapter da = new SqlDataAdapter(cmd);
    16 DataSet ds = new DataSet();
    17 da.Fill(ds);
    18 this.GridView1.DataSource = ds.Tables[0];
    19 this.GridView1.DataBind();
    20 }
    21 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    22 {
    23 foreach (TableCell item in e.Row.Cells)
    24 {
    25 item.Attributes.Add("style", "border-color:black");
    26
    27 }
    28 }
    29 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    30 {
    31 if (e.Row.RowType == DataControlRowType.Header)
    32 {
    33 TableCellCollection tc = e.Row.Cells;
    34 tc.Clear();
    35 tc.Add(new TableHeaderCell());
    36 tc[0].Attributes.Add("colspan", "6");
    37 tc[0].Attributes.Add("bgcolor", "#006699");
    38 tc[0].Text = "全部信息</th></tr><tr>";
    39 tc.Add(new TableHeaderCell());
    40 tc[1].Text = "编号";
    41 tc[1].Attributes.Add("bgcolor", "DarkSeaGreen");
    42 tc.Add(new TableHeaderCell());
    43 tc[2].Attributes.Add("colspan", "2");
    44 tc[2].Attributes.Add("bgcolor", "LightSteelBlue");
    45 tc[2].Text = "基本信息";
    46 tc.Add(new TableHeaderCell());
    47 tc[3].Attributes.Add("colspan", "2");
    48 tc[3].Attributes.Add("bgcolor", "DarkSeaGreen");
    49 tc[3].Text = "联系方式";
    50 tc.Add(new TableHeaderCell());
    51 tc[4].Attributes.Add("bgcolor", "LightSteelBlue");
    52 tc[4].Text = "福利</th>";
    53
    54 }
    55 }
    怀揣着一点点梦想的年轻人
    相信技术和创新的力量
    喜欢快速反应的工作节奏
  • 相关阅读:
    CAS实战の自定义注销
    CAS实战の自定义登录
    MongoDB学习总结
    Django登录使用的技术和组件
    Docker搭建Hadoop环境
    配置Nginx的坑及思路
    Centos7 升级 sqlite3
    Python基础题
    pandas的数据筛选之isin和str.contains函数
    CentOS7 下Docker最新入门教程 超级详细 (安装以及简单的使用)
  • 原文地址:https://www.cnblogs.com/hfliyi/p/1982810.html
Copyright © 2011-2022 走看看