如果Column具有“total”,则更改网格行颜色在里面 [英] Change grid row color if Column has "total" in it
本文介绍了如果Column具有“total”,则更改网格行颜色在里面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public partial class gridBind : System.Web.UI.Page
{
public SqlConnection con = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
if(!(IsPostBack))
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
SqlDataAdapter adp = new SqlDataAdapter(";with cte as ( SELECT SLHD.VOUCH_DATE, '' as [Vouch_Date_Descr] ,SUM(SLTXN.CALC_NET_AMT) AS AMT,SUM(SLTXN.TOT_QTY) AS QTY FROM SL_HEAD20132014 AS SLHD,ACCOUNTS AS ACT,SL_TXN20132014 AS SLTXN WHERE SLHD.ACT_CODE=ACT.ACT_CODE AND SLTXN.VOUCH_CODE=SLHD.VOUCH_CODE GROUP BY SLHD.VOUCH_CODE,SLHD.VOUCH_DATE,SLHD.VOUCH_NUM,ACT.ACT_NAME ) ,cte1 as ( SELECT SLHD.[VOUCH_DATE],case when SlHD.vouch_date=0 then 'pending' Else 'Total' End as [Vouch_Date_Descr] ,SUM(SLTXN.CALC_NET_AMT) AS AMT,SUM(SLTXN.TOT_QTY) AS QTY FROM SL_HEAD20132014 AS SLHD,ACCOUNTS AS ACT,SL_TXN20132014 AS SLTXN WHERE SLHD.ACT_CODE=ACT.ACT_CODE AND SLTXN.VOUCH_CODE=SLHD.VOUCH_CODE GROUP BY SLHD.VOUCH_DATE WITH CUBE ) Select * From ( Select * From cte Union All Select * From cte1 ) A ORDER BY A.VOUCH_DATE,A.VOUCH_DATE_DESCR ", con);
DataSet ds = new DataSet();
adp.Fill(ds);
grdRecord.DataSource = ds;
grdRecord.DataBind();
}
}
}
VOUCH_DATE Vouch_Date_Descr AMT QTY
Total 67624.0000 598.0000
12/5/2013 00:00:00 1271.0000 16.0000
12/5/2013 00:00:00 Total 1271.0000 16.0000 // want to make it green
12/6/2013 00:00:00 220.0000 1.0000
12/6/2013 00:00:00 220.0000 1.0000
12/6/2013 00:00:00 540.0000 4.0000
12/6/2013 00:00:00 Total 980.0000 6.0000 // want to make it green
12/13/2013 00:00:00 600.0000 2.0000
12/13/2013 00:00:00 Total 600.0000 2.0000 // want to make it green
推荐答案
您可以使用GridView RowDataBound事件并检查您的条件
You can use, GridView RowDataBound event and check your condtion over there
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//row represent you currently bindweed data row, like row of your data table
System.Data.DataRow row = (System.Data.DataRow)e.Row.DataItem;
//here i have just show how to check you need to add your orignal condition to check here
if (row["YourColumn"] == "Total") // Check your condition
{
e.Row.CssClass = "green";
}
else
{
e.Row.CssClass = "normal";
}
}
}
这篇关于如果Column具有“total”,则更改网格行颜色在里面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文