Sorting Gridview in Visual Basic

I am trying to sort a gridview in visual basic using the following method, however the second line of code (Dim dv as DataView...) throws a NullReferenceException. When I debug the code and step through it, I can see that the DataTable dt has a value of "Nothing" after it is instantiated. Any help would be greatly appreciated.

        Dim dt As DataTable = grdExpProd.DataSource
        Dim dv As DataView = dt.DefaultView

        If (blnExTraining) Then
            dv.Sort = "ExpirationDate DESC"
            dv.Sort = "ExpirationDate ASC"
        End If

        grdExpProd.DataSource = dv


After postback the DataSource of any Web-Databound-Control like GridView is Nothing (null in C#). Note that HTTP is stateless, all objects that are created in a page's life-cycle will be destroyed as soon as the page was rendered.

So the solution is easy, select the DataSource again with the correct ORDER BY.

Need Your Help

Howto easily create a diagram using firebug loading and/or executing times?

performance firebug diagram pie-chart

I need to create diagram showing the most time consuming tasks when a specific page gets loaded.

PHP can't find a function in my class

php namespaces

I have a class that is getting called and for some reason one of the functions I have is being found, but the other one is not. Here is my code:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.