Solved

grid view cell text problem

Posted on 2011-09-11
6
292 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

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
Comment Utility
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
Comment Utility
code that worked for me
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Author Closing Comment

by:AhmedHindy
Comment Utility
worked for me
0
 
LVL 4

Author Comment

by:AhmedHindy
Comment Utility
worked
0
 
LVL 4

Author Comment

by:AhmedHindy
Comment Utility
worked
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now