【下面是我的代码】
        protected void grv_CustomerIncomeTbl_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            string grvtittle = "";//*号
            for (int i = 0; i < this.grv_CustomerIncomeTbl.Rows.Count ; i++) 
            {
                grvtittle = grv_CustomerIncomeTbl.Rows[i].Cells[12].Text;
                if (grvtittle == "1")
                {
                    grv_CustomerIncomeTbl.Rows[i].Cells[12].Text = "*";
                }
                else
                {
                    grv_CustomerIncomeTbl.Rows[i].Cells[12].Text = "";
                }
            }
        } 我想要的事 当Cells[12].Text值等于1时 就显示*号 但是现在有个问题  当数据多时 就会把它给覆盖了
也就是 本来第一行时="1" 就显示*  当循环到地二行时 第二行的数据="0" 就不显示*  但是现在回把第一行的数据也付成“”了   请大家帮帮忙 解决下·!

解决方案 »

  1.   

      在方法内
      加上类别判断  if (e.Row.RowType == DataControlRowType.DataRow)
      { }
      

  2.   

    RowDataBound事件每行绑定的时候执行一次,所以不需要循环
            protected void grv_CustomerIncomeTbl_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                    string grvtittle = "";//*号
                    grvtittle = e.Row.Cells[12].Text;
                    if (grvtittle == "1")
                    {
                        e.Rows.Cells[12].Text = "*";
                    }
                    else
                    {
                        e.Row.Cells[12].Text = "";
                    }
            } 
      

  3.   


            protected void grv_CustomerIncomeTbl_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if(e.Row.RowType == DataControlRowType.DataRow)
                    e.Row.Cells[12].Text = e.Row.Cells[12].Text == "1" ? "*" : "";
            } 
      

  4.   

    试试这样写        string grvtittle = "";//*号 
            GridViewRow row = e.Row;
            if (RowType != DataControlRowType.Header && RowType != DataControlRowType.Footer)
            {
                grvtittle = grv_CustomerIncomeTbl.Rows[row.RowIndex].Cells[12].Text;
                if (grvtittle == "1")
                {
                    grv_CustomerIncomeTbl.Rows[row.RowIndex].Cells[12].Text = "*";
                }
                else
                {
                    grv_CustomerIncomeTbl.Rows[row.RowIndex].Cells[12].Text = "";
                }
            }
      

  5.   

    对了,还要加上3楼的行判断 - -
    if (e.Row.RowType == DataControlRowType.DataRow)
    { }
      

  6.   

     谢谢楼上 几位帮助  
    我改成模板列 就解决了  呵呵  分一样照给! if (e.Row.RowType == DataControlRowType.DataRow) 
                { 
                    Label text = (Label)e.Row.FindControl("lbl_Czq"); 
                    if (text.Text == "1") 
                    { 
                        text.Text = "*"; 
                    } 
                    else 
                    { 
                        text.Text = ""; 
                    } 
                }