I have an asp ListView that is currently bound to an ObjectDataSource. The ObjectDataSource’s select method has a parameter that is tied to a hidden Label. Thus to clear my ListView I simply have my hidden Label’s text property set to string.Empty and bind the ListView’s data. This works great, however if a user clicks one of my ListView <th> Labels, which sorts the ListView, and then clicks the “Clear” button it throws a System.IndexOutOfRangeException: Cannot find column name.
This is the only time this Exception is thrown, if the ListView is cleared without being sorted first everything is hunky dory.
Any help is appreciated
I presume that when the label is blanked your datasource is returning nothing, not even a table schema. This will mean that your ListView will have no data including no concept of what the columns might be. Thus when you are telling it to sort on a certain column it is complaining that it can’t find that column.
I would imagine the two easiest fixes would be to remove the sort column when you clear it or to make sure that the ListView always knows what columns it has at least.