c# GridVeiw1_DataBound

protected void GridVeiw1_DataBound(object sender, GridViewRowEventArgs e)
        {


            if (e.Row.RowType == DataControlRowType.Header)
            {
                //for (int i = 0; i < e.Row.Cells.Count; i++) { e.Row.Cells[i].Text = fnames[i]; e.Row.Cells[i].Attributes.Add("nowarp", "nowarp"); }
                TableCellCollection tcHeader = e.Row.Cells;
                tcHeader.Clear();
                //第一行
                tcHeader.Add(new TableHeaderCell());
                tcHeader[0].Attributes.Add("colspan", "9");
                tcHeader[0].Attributes.Add("style", "height:35px;text-align:center;");
                tcHeader[0].Text = this.Title + "</th></tr><tr>";

                //第二行
                tcHeader.Add(new TableHeaderCell());
                tcHeader[1].Text += "编号";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[2].Text += "字段1";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[3].Text += "字段2";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[4].Text += "字段3";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[5].Text += "字段4";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[6].Text += "字段5";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[7].Text += "字段6";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[8].Text += "字段7";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[9].Text += "字段8</th></tr><tr>";

            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#EDF1D5'");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
                //鼠标点击行时设置底色

                //e.Row.Attributes.Add("onclick", "this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';");
                e.Row.Cells[0].Text = (e.Row.RowIndex + this.GridView1.PageIndex * this.GridView1.PageSize + 1).ToString();

                //3
                //e.Row.Cells[3].Text = e.Row.Cells[3].Text.Trim() == "1" ? "男" : "女";
                //e.Row.Cells[12].Text = e.Row.Cells[12].Text.Trim() == "1" ? "男" : "女";
                //e.Row.Cells[10].Text = e.Row.Cells[10].Text.Trim() == "1" ? "男" : "女";
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值