Solved

grid view cell text problem

Posted on 2011-09-11
6
295 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:AhmedHindy
  • 4
6 Comments
 
LVL 40
ID: 36519091
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

0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36520884
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;
 }

}
0
 
LVL 4

Accepted Solution

by:
AhmedHindy earned 0 total points
ID: 36556440
code that worked for me
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 4

Author Closing Comment

by:AhmedHindy
ID: 36585510
worked for me
0
 
LVL 4

Author Comment

by:AhmedHindy
ID: 36556462
worked
0
 
LVL 4

Author Comment

by:AhmedHindy
ID: 36556464
worked
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question