Link to home
Start Free TrialLog in
Avatar of AhmedHindy
AhmedHindyFlag for Egypt

asked on

grid view cell text problem

am trying to  get the value of the cell of grid view
if it is
"abc"
change the back ground of grid row
but
_grid.Rows[index].Cells[1].Text

always get the result = ""
any help ??????????
private void FormateGrid(GridView _grid)
    {
        for (int i = 0; i < _grid.Rows.Count; i++)
        {
            if (_grid.Rows[i].Cells[1].Text.Contains("abc"))
            {
                _grid.Rows[i].BackColor = System.Drawing.Color.Blue;

            }
        }
    }

Open in new window

Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

A DataGridViewRow is not a Control, it does not have a BackColor property. Instead of BackColor, you change its color through its style:
_grid.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Blue;

Open in new window

Avatar of Kiran Sonawane
Try like this

foreach (GridViewRow gvrow in _grid.Rows)
{
//Assuming you are finding text which in label
Label lbl = (Label)gvrow.FindControl("Label1");
if(lbl!= null)
 {
   string search_text = lbl.Text;
 }

}
ASKER CERTIFIED SOLUTION
Avatar of AhmedHindy
AhmedHindy
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AhmedHindy

ASKER

worked for me
worked
worked