0

我一直遇到一个看起来很简单的问题,但我不知道出了什么问题。我是 Asp 的新手,因此不了解调试基础知识。

我正在尝试根据结果列中的值更改单元格文本的颜色。我附上了代码供您参考。请告诉我出了什么问题,没有任何反应。

                <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;

                }
            }

        }
    }
}

我已经尝试过stackoverflow中的所有解决方案,有人可以帮我调试一下吗?我添加了断点并检查了。看起来 if 条件失败了

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

,因为它不会继续进入这个条件,而是返回调用函数。我还尝试删除计时器。

4

1 回答 1

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;
            }
于 2013-08-29T11:39:27.830 回答