Click here to Skip to main content
Click here to Skip to main content

How to manipulate a GridView cell in ASP.NET

By , 7 May 2013
 

Introduction

Here I will show you how to manipulate the grid view cell styles in a Windows Forms application. For this, I will get all the grid view rows and compare the grid view header cell value with the drop down selected value. Then the related data cell's back color will be changed to Green. In the foreach loop, we have one more for loop to get the entire column cells of the related header in the GridView.

foreach(DataGridViewRow row in this.Gvorders.Rows)
{
    if (row.HeaderCell.Value == txtorder.Text)
    {
        for (int i = 0; i < Gvorders.Columns.Count; i++)
        {
            this.Gvorders.CurrentCell = row.Cells[i];
            row.Cells[i].Style.BackColor = Color.Green;
        }
    }
}

VB

For Each row As DataGridViewRow In Me.Gvorders.Rows
    If row.HeaderCell.Value = txtorder.Text Then
        For i As Integer = 0 To Gvorders.Columns.Count - 1
            Me.Gvorders.CurrentCell = row.Cells(i)
            row.Cells(i).Style.BackColor = Color.Green
        Next
    End If
Next

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

bhaskarareddy
Software Developer
India India
Member
Have been working as a software developer for 3 years.I passionate to share my practical knowledge in development to others
 
Bhaskar
Http://csharpektroncmssql.blogspot.com

Comments and Discussions

Comment 1 message has been posted for this article Visit http://www.codeproject.com/Tips/387941/How-to-manipulate-a-GridView-cell-in-ASP-NET to post and view comments on this article, or click here to get a print view with messages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130513.1 | Last Updated 7 May 2013
Article Copyright 2012 by bhaskarareddy
Everything else Copyright © CodeProject, 1999-2013
Terms of Use