2013-08-28 150 views
0

我一直坚持一个看起来很简单的问题,但我不知道什么是错的。我是Asp的新手,因此我不了解调试的基础知识。条件单元格格式格式化不在asp.net中发生

我想根据结果列中的值更改单元格文本的颜色。我附上了供您参考的代码。请告诉我什么是错误的,nothign越来越反映。

   <AlternatingRowStyle CssClass="alt" /> 

       <Columns> 

        <asp:BoundField DataField="TestCaseID" HeaderText="TestCaseID" SortExpression="TestCaseID" /> 
        <asp:BoundField DataField="Iteration" HeaderText="Iteration" SortExpression="Iteration" /> 
        <asp:BoundField DataField="StartTime" HeaderText="StartTime" SortExpression="StartTime" /> 
        <asp:BoundField DataField="EndTime" HeaderText="EndTime" SortExpression="EndTime" /> 
        <asp:BoundField DataField="Result" HeaderText="Result" SortExpression="Result" /> 
        <asp:BoundField DataField="Comments" HeaderText="Comments" SortExpression="Comments" /> 
       </Columns> 


       <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> 
       <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> 
       <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" /> 
       <RowStyle BackColor="#FFFBD6" ForeColor="#333333" /> 
       <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" /> 
       <SortedAscendingCellStyle BackColor="#FDF5AC" /> 
       <SortedAscendingHeaderStyle BackColor="#4D0000" /> 
       <SortedDescendingCellStyle BackColor="#FCF6C0" /> 
       <SortedDescendingHeaderStyle BackColor="#820000" /> 
      </asp:GridView> 
      <asp:EntityDataSource ID="EntityDataSource1" runat="server" 
       ConnectionString="name=Test_Manager_DatabaseEntities" 
       DefaultContainerName="Test_Manager_DatabaseEntities" 
       EnableFlattening="False" EntitySetName="TestExecutionDetails" 
       Where="it.[TestExecutionID] = @ExecutionID "> 
       <WhereParameters> 
        <asp:QueryStringParameter Name="ExecutionID" QueryStringField="ExecutionID" Type="Int32" /> 
       </WhereParameters> 
      </asp:EntityDataSource> 
      <asp:QueryExtender ID="ctlMyQueryExtender" runat="server" TargetControlID="EntityDataSource1"> <asp:SearchExpression DataFields="Result" SearchType="StartsWith"> <asp:ControlParameter ControlID="TextBoxName" /></asp:SearchExpression> </asp:QueryExtender> 
     </ContentTemplate> 
    </asp:UpdatePanel> 


using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

namespace ABCD 
{ 
    public partial class TestExecutionResults : System.Web.UI.Page 
    { 
     private int TestExecID; 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      //Response.Cache.SetCacheability(HttpCacheability.NoCache); 
      //Response.CacheControl = "no-cache"; 
      if (!Page.IsPostBack) 

       using (Test_Manager_DatabaseEntities entities = new Test_Manager_DatabaseEntities()) 
       { 
        Console.WriteLine(Request.QueryString["ExecutionID"]); 
        TestExecID = Convert.ToInt32(Request.QueryString["ExecutionID"]); 
       } 
} 

protected void Timer2_Tick(object sender, EventArgs e) 
     { 

      GridView1.DataBind(); 

     } 

     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
     { 
      if (e.Row.RowType == DataControlRowType.DataRow) 
      { 
       if (e.Row.Cells[4].Text == "Pass") 
       { 
        e.Row.Cells[4].ForeColor = System.Drawing.Color.Green; 
       } 

       else if (e.Row.Cells[4].Text == "Fail") 
       { 
        e.Row.Cells[4].ForeColor = System.Drawing.Color.Red; 

       } 
      } 

     } 
    } 
} 

我曾尝试在计算器所有的解决方案,能有人帮我调试此。我添加了断点并进行了检查。它看起来像条件​​是失败

if (e.Row.RowType == DataControlRowType.DataRow) 

,因为它不会继续到这个条件,而是它回到调用该函数。我也尝试通过删除计时器。

回答

0

这是一个简单的错误,

if (e.Row.Cells[4].Text.Trim().ToLower() == "pass") 
      { 
       e.Row.Cells[4].ForeColor = System.Drawing.Color.Green; 
      } 
      else 
      { 
       e.Row.Cells[4].ForeColor = System.Drawing.Color.Red; 
      } 
相关问题