Setting ObjectDataSource Select Parameters at RunTime

I had a need to set some of the ObjectDataSource parameters for my select statement at runtime. Sometimes the parameters are set from a cookie, other times from a querystring and sometimes from a form field.

To set the parameters at runtime, you need to implement the Selecting Event for the ObjectDataSource and then use the InputParameter for the ObjectDataSourceSelectingEventArgs to set the value.

Example:

protected void ObjectDataSource1_Selecting(object sender,ObjectDataSourceSelectingEventArgs e)
{
e.InputParameters["MyParameterName"] = ParameterValue;
}


WebForms and TDD

Interesting post on Webforms and testability. There is also a great comment by Scott Gunthrie (ScottGu) that has a lot of great information in it.

http://codebetter.com/blogs/jeremy.miller/archive/2007/03/07/Jay_2700_s-TDD-QuickStart_2C00_-and-the-underlying-problems-he-stumbled-into.aspx?CommentPosted=true#commentmessage


Gotcha with gridview custom paging and disabled viewstate

I ran into a problem with a GridView with custom paging throwing a arithmetic overflow error when I click on the Last pager button. It turns out for whatever reason, Microsoft stores the GridView's total page count in viewstate instead of the control state like the rest of the GridView properties. Luckily it is really easy to work around this issue. All you need to do is change the Last pager button's command argument in the code-behind to the GridView.PageCount property and the error goes away.


NHibernate, ActiveRecord and SQL2005

Recently I needed to do paging for a GridView using an ObjectDataSource and ActiveRecord. I wanted to use the SQL2k5 ROW_NUMBER function that I blogged about in this post to do real paging in sql but everything I had seen on using NHibernate with SQl2k5 said to use the SQL2k dialect. There was no indication that a SQL2k5 dialect even existed. However, during a search for another NHibernate question, I found a SQL2k5 dialect that someone had written to do exactly what I wanted. The code was available off the NHibernate contrib. site so I figured it worked and I could integrate it into my solution. As I was looking to figure out how dialects are integrated, I found that the dialect is already part of the NHibernate 1.2 release but none of the documents are updated to reflect this. To use the dialect, you just need to set <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect"/> in your ActiveRecord configuration.


Update ActiveRecord CodeSmith Template

I have updated my ActiveRecord CodeSmith template to provide support for one-to-one relationships and fixed a bug with the naming of the many-to-many private variable/public property in the generate code.

Download ActiveRecord.zip