gridview行颜色 [英] gridview row colors

查看:142
本文介绍了gridview行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GridView模板显示数据,这里我有两列实际值,估计费用.如果实际成本超过了估算成本(然后是估算的实际成本),我必须在GridView中动态更改该行的颜色.

I am using GridView templates for displaying data, Here i have two columns actual, estimate costs. If there actual cost cross the estimate cost(actual cost grater then estimated), I have to change that row color dynamically in GridView.

推荐答案

Handle RowDataBound GridView事件,然后在那儿应用您的逻辑.

RowDataBound 事件将在DataBound
Handle RowDataBound event of the GridView and apply your logic over there.

RowDataBound event will fire at every row which is created while DataBound


创建的每一行触发,对于Datagrid事件为"ItemDataBound",对于Gridview事件为"RowDataBound" '.

样本:
For Datagrid the event is ''ItemDataBound'' and for Gridview the event is ''RowDataBound''.

sample:
protected void DataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
     Textbox tbx1 = (TextBox)e.Row.FindControl("ActualCostTextbox");
     Textbox tbx2 = (TextBox)e.Row.FindControl("EstimatedCostTextbox");
     if (tbx1 != null & tbx2 != null)
     { 
         // compare, validate the values of tbx1 & tbx2
         // you got tbx1.Text & tbx2.Text value here. 
         // Do any calculation desired.
         // based on it logic, set the CSS of the row.
     }
}


尝试一下
protected void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
  {
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
      Textbox tbx1 = (TextBox)e.Row.FindControl("ActualCostTextbox");
      Textbox tbx2 = (TextBox)e.Row.FindControl("EstimatedCostTextbox");
      if (tbx1 != null&&tbx2 != null)
      {
         // Your code.....
      }
    }
  }


这篇关于gridview行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆