ObjectDataSource.SelectCountMethod wants an int
I have been working with the GridView ASP.NET control today, bound to an ObjectDataSource. This is to do with my experiment with DBMail that I mentioned the other day. It wasn’t working. I couldn’t find a solution on the net. By chance, I changed this:
class DatabaseSource { long _messageCount = 0; public List GetMessages(long startRow, int pageSize) { Database db = new Database(); List messages = db.GetMessages( startRow, pageSize, out _messageCount); return messages; } publiclong GetMessageCount() { return _messageCount; } }
into this:
class DatabaseSource { long _messageCount = 0; public List GetMessages(long startRow, int pageSize) { Database db = new Database(); List messages = db.GetMessages( startRow, pageSize, out _messageCount); return messages; } publicint GetMessageCount() { return Convert.ToInt32(_messageCount); } }
Notice the difference?
To get the ObjectDataSource to work, the SelectCountMethod has to return an 32-bit integer (System.Int32). It failed (without an error message) when it was provided with a long or 64-bit integer (System.Int64).
It turns out it’s written in the documentation in black and white:
Type: System.String
A string that represents the name of the method or function that the ObjectDataSource uses to retrieve a row count. The method must return an integer (Int32). The default is an empty string ("").
Who would have thought?
Hopefully this will save someone who is running into the same problem. (That’s assuming that this will pop up in their search results when they search for ObjectDataSource and GridView paging not working!)
Member discussion