首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GridView RowDataBound For循环不工作

GridView RowDataBound For循环不工作
EN

Stack Overflow用户
提问于 2014-10-06 00:42:40
回答 1查看 737关注 0票数 0

我有一个类似于下面的专栏

1 1 5 1 1 1 5 1 1 1 2 1

2 3 1 1 1 3

我想要做的是突出显示5到5之间的所有内容,以及2到2之间的所有内容,等等。然而,下面的脚本在第一部分之后停止。我希望它循环遍历网格视图中的所有行。

代码

代码语言:javascript
复制
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        for (int i = 0; i < 1; i++)
        {
            bool begin = false;
            foreach (GridViewRow row in GridView1.Rows)
            {
                if (row.Cells[i + 2].Text != "1")
                {
                    row.Cells[i + 2].BackColor = System.Drawing.Color.Blue;
                    if (!begin) begin = true;
                    else
                        break;
                }
                if (begin) row.Cells[i + 2].BackColor = System.Drawing.Color.Blue;
            }
        }
    }

/code

EN

回答 1

Stack Overflow用户

发布于 2014-10-06 17:03:24

像这样的东西可以工作吗?

代码语言:javascript
复制
 GridViewRow row = e.Row;            
        int firstindex = 0;
        int Lastindex = 0;
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string value = e.Row.Cells[0].Text;               
            firstindex = value.IndexOf('5');
            Lastindex = value.LastIndexOf('5');
            string refinedVal = value.Substring(0, firstindex);
            string refinedVal1 = value.Substring(firstindex + 1, Lastindex);
            string refinedVal2 = value.Substring(Lastindex);
            string finalop = refinedVal + "<span style='color:blue'>" + refinedVal1 + @"</span>" + refinedVal2;
            row.Cells[0].Text = string.Empty;
            row.Cells[0].Text = finalop;
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26204837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档