Solved

grid view cell text problem

Posted on 2011-09-11
6
296 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 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