Solved

grid view cell text problem

Posted on 2011-09-11
6
294 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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