I have bound my ListView to a database. I've used SqlDataSource to do the work. I want to change the datasource programatically but this is where it all goes wrong. I try to get the current datasource by doing so:
SqlDataSource oldSource = lstContacts.DataSource as SqlDataSource;
Then I want to save the SelectCommand of the SqlDataSource in a string:
string oldSelectCommand = oldSource.SelectCommand;
I am doing this because I want to check if the select statement contains an order by clause and if it does, to take it away and change it with another order by clause :)
However, I am getting this:
"System.NullReferenceException: Object reference not set to an instance of an object."
Anyone? Please (: