aspx GridView的RowDataBound中改变单元格大小,颜色,汇总等

 

 protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[0].Attributes.Add("style", "width:40px");
        e.Row.Cells[1].Attributes.Add("style", "width:60px");
        e.Row.Cells[2].Attributes.Add("style", "width:60px");
        e.Row.Cells[3].Attributes.Add("style", "width:60px");
        e.Row.Cells[4].Attributes.Add("style", "width:60px");
        e.Row.Cells[5].Attributes.Add("style", "width:75px");
        e.Row.Cells[6].Attributes.Add("style", "width:75px");
        e.Row.Cells[7].Attributes.Add("style", "width:75px");
        e.Row.Cells[8].Attributes.Add("style", "width:75px");
        e.Row.Cells[9].Attributes.Add("style", "width:75px");
        e.Row.Cells[10].Attributes.Add("style", "width:75px");
        e.Row.Cells[11].Attributes.Add("style", "width:110px");
        e.Row.Cells[12].Attributes.Add("style", "width:110px");
        e.Row.Cells[13].Attributes.Add("style", "width:110px");
        e.Row.Cells[14].Attributes.Add("style", "width:140px");
        e.Row.Cells[15].Attributes.Add("style", "width:40px");
        e.Row.Cells[16].Attributes.Add("style", "width:40px");
      
  
      
         if (e.Row.RowType == DataControlRowType.DataRow)
         {

             e.Row.Cells[5].ForeColor = System.Drawing.Color.DarkRed;
             e.Row.Cells[6].ForeColor = System.Drawing.Color.DarkBlue;
             e.Row.Cells[7].ForeColor = System.Drawing.Color.DarkGreen;
             e.Row.Cells[8].ForeColor = System.Drawing.Color.DarkRed;
             e.Row.Cells[9].ForeColor = System.Drawing.Color.DarkBlue;
 
             DataRowView dr = e.Row.DataItem as DataRowView;
             if (dr.Row[bilv].ToString().Trim() == "")
             {

             }
             else
             {
                 numbil += Convert.ToDouble(dr.Row[bilv]);

                 if (Convert.ToDouble(dr.Row[bilv]).ToString().Split('.')[0] == "0" || Convert.ToDouble(dr.Row[bilv]).ToString().Split('.')[0] == "-0")
                 {
                     e.Row.Cells[13].Text = "0";
                 }
                 else
                 {
                     //Math.Round(Convert.ToDouble(Convert.ToDouble(dr.Row[bilv]).ToString().Split('.')[0]), 2, MidpointRounding.AwayFromZero);

                     e.Row.Cells[13].Text = Math.Round(Convert.ToDouble(Convert.ToDouble(dr.Row[bilv]).ToString().Split('.')[0]), 0, MidpointRounding.AwayFromZero).ToString();
                 }

             }
             if (dr.Row[bidui].ToString().IndexOf("-") >= 0)
             {
                 e.Row.Cells[11].ForeColor = System.Drawing.Color.Red;
             }
             if (dr.Row[fuzhi].ToString().IndexOf("-") >= 0)
             {
                 e.Row.Cells[12].ForeColor = System.Drawing.Color.Red;
             }
             if (dr.Row[bilv].ToString().Trim() == "")
             {

             }
             else
             {
                 if (e.Row.Cells[13].Text.IndexOf("-") >= 0)
                 {
                     e.Row.Cells[13].ForeColor = System.Drawing.Color.Red;
                 }
             }
 
           

            
           num += Convert.ToDouble(dr.Row[bidui]);
           numfz += Convert.ToDouble(dr.Row[fuzhi]);
             i++;
         }  
         else if (e.Row.RowType == DataControlRowType.Footer)  
         {  
             //Label LabelAll =  e.Row.FindControl("labelAll") as Label;  
             //if (LabelAll != null)    
             //{      
             //    LabelAll.Text += num.ToString();//"计算的总数,或者也可以单独计算";//  
             //}
           e.Row.Cells[0].Text = "共 "+i+"条";
           e.Row.Cells[10].Text = "总计:";
            e.Row.Cells[11].Text =  num.ToString();
           e.Row.Cells[12].Text = numfz .ToString();
           e.Row.Cells[13].Text = numbil.ToString();
  

         }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值