Click here to Skip to main content
13,055,408 members (54,092 online)
Click here to Skip to main content
Add your own
alternative version


6 bookmarked
Posted 20 May 2012

How to manipulate a GridView cell in ASP.NET

, 7 May 2013
Rate this:
Please Sign up or sign in to vote.
This tip discusses how to manipulate a GridView cell in ASP.NET.


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</code />.

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;


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
    End If


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


About the Author

Software Developer
India India
Have been working as a software developer for 5 years.I passionate to share my practical knowledge in development to others


You may also be interested in...

Comments and Discussions

GeneralMy vote of 4 Pin
pratapvarun21-May-12 3:31
memberpratapvarun21-May-12 3:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 7 May 2013
Article Copyright 2012 by bhaskarareddy
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid