resetting gridView SelectedRow.BackColor

Posted on 2009-04-16
Last Modified: 2013-12-26
I currently have a gridView (gv_news) and a detailsView, the gridView shows a list of news items, with an alternatingRowStyle backColor of Grey and Transparent. The gridView also has a selectedRowStyle backColor of green:
<SelectedRowStyle BackColor="#CCFFCC" />
<AlternatingRowStyle BackColor="#EFEFEF" />

Now when I select an item in the grid view the item turns green, once I update the item or cancel the update in the detailsView I would like the selectedRowStyle in the gridView to be reset to the default alternatingRowStyle - as if nothing is selected any more.

I have created a function which I have bound the the detailsViews Update and Cancel buttons as show below. The error I receive, when one of these buttons is clicked is:
System.NullReferenceException: Object reference not set to an instance of an object.

I would appreciate some assistance in resolving this.

Many thanks,

Sub selectRemove()

    Dim gv_news As GridView = CType(Page.FindControl("gv_news"), GridView)

    gv_news.SelectedRow.BackColor = Drawing.Color.Transparent

End Sub

Open in new window

Question by:badstyle
    1 Comment
    LVL 14

    Accepted Solution


    It is very simple. After updating the database, before rebinding to the dataset, do the following


    It will reset the background color back to normal

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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!

    Suggested Solutions

    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    737 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

    21 Experts available now in Live!

    Get 1:1 Help Now