写一个根据某列数值改变GridView中某行颜色的程序

78 篇文章 0 订阅

    这一阶段写一个在线Web预订系统, 在完成预订单管理这块时候碰到一个设计思想是根据预订单流转的具体流程在gridview中改变相应颜色的内容,这时候正好碰到www.yesky.com上asp.net 2.0中Gridview控件高级技巧这篇文章中的一段例子

 

  protected   void  GvSubscribe_RowDataBound( object  sender, GridViewRowEventArgs e)
    
{
        
if (e.Row.RowType == DataControlRowType.DataRow)
        
{
            
int tempFlowId = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "FlowId"));
            
            
if (tempFlowId == 1)
                e.Row.BackColor 
= Color.Blue;
            
if (tempFlowId == 2)
                e.Row.BackColor 
= Color.Red;
            
if (tempFlowId == 3)
                e.Row.BackColor 
= Color.Green;
            
if (tempFlowId == 4)
                e.Row.BackColor 
= Color.Gray;
        }

        
         

    }

 

aspx页面文件为

 

  < table style = " height: 16px;  width: 564px; "  cellpadding  = 0  cellspacing >
                       
< tr >< td >
                           未预订:草绿色 已预订:黄色 已烧录:兰色 已审批:红色 已回复:黑色
</ td ></ tr >
                       
< tr >
                       
< td style = " height: 250px;text-align: left;  width:564px; " >< asp:GridView ID = " GvSubscribe "  runat = " server "  AllowPaging = " True "  AllowSorting = " True "
                            AutoGenerateColumns
= " False "  DataSourceID = " SqlDataSource2 "  Width = " 580px "  Height = " 1px "  OnRowDataBound = " GvSubscribe_RowDataBound " >
                            
< Columns >
                                
< asp:BoundField DataField = " PriId "  HeaderText = " 优先级 "  SortExpression = " PriId "   />
                                
< asp:BoundField DataField = " WorkId "  HeaderText = " 施工人员工号 "  SortExpression = " WorkId "   />
                                
< asp:BoundField DataField = " SubscriptionTitle "  HeaderText = " 预订单标题 "  SortExpression = " SubscriptionTitle "   />
                                
< asp:BoundField DataField = " SubscriptionOrderContent "  HeaderText = " 预约订单内容 "  SortExpression = " SubscriptionOrderContent "   />
                                
< asp:BoundField DataField = " WorkMaincontentId "  HeaderText = " 施工工作事由Id号 "  SortExpression = " WorkMaincontentId "   />
                                
< asp:BoundField DataField = " FlowId "  HeaderText = " 流程号 "  SortExpression = " FlowId "   />
                                
< asp:BoundField DataField = " AddDate "  HeaderText = " 增加时间日期 "  SortExpression = " AddDate "   />
                                
< asp:BoundField DataField = " DepartmentId "  HeaderText = " 部门号 "  SortExpression = " DepartmentId "   />
                                
< asp:CommandField ShowEditButton = " True "   />
                            
</ Columns >
                        
</ asp:GridView >
                        
< asp:SqlDataSource ID = " SqlDataSource2 "  runat = " server "  ConnectionString = " <%$ ConnectionStrings:OnlineSuscribeSystemConnectionString3 %> "
                            SelectCommand
= " SELECT [SubscriptionTitle], [PriId], [WorkId], [SubscriptionOrderContent], [WorkMaincontentId], [FlowId], [AddDate], [DepartmentId] FROM [SubscriptionOrder] "  DataSourceMode = " DataSet " >
                        
</ asp:SqlDataSource >
                        
& nbsp; & nbsp; </ td ></ tr >
                        
</ table >
                        
结果发现tempFlowId始终为0,按照csdn在线图书asp.net 2.0技术内幕中的描述,DataBinder.Eval绑定器是两个重载方法,三个参数的最后一个是格式化数据类型,返回数值都是对象,如果用Convert.ToInt32都应该能够正确返回那个类的数值,后来查找页面文件与那篇文章之间的区别才知道其中的SqlDataSource中要设置DataSourceMode="DataReader",而先前没有设置,相反,如果我将其设置成为DataSet却发现不能分页,现在这样一折腾一个上午加一个下午,感觉有解决问题的快感,但是原因找到了,希望和大家共勉...
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值