You are not Logged in
Would you like to Login or Register

Today is: Wednesday, 07 January, 2009
Check this months hot topics

Parameter Order Wrong With ObejctDataSource

This one came up today and I felt in a sharing mood. I had a GridView using and ObjectDataSource (ODS) and this was used for automatic updates via Inplace editing. When updating the GridView this would then call the UpdateMethod of the ObjectDataSource, but it would fail with the above error.

After a little playing, it turns out that if you have got some of your columns in a GridView set to ReadOnly Visible=false, then there is no way of guranteeing the order of the parameters passed through to the UpdateMethod of the ODS.

To get around this little problem, you can either create an Update Method on your Custom Object that supports the method signature being passed through, or the better option is to hack the parameter order that is passed through.

In order to change order of the Parameters passed through you need to hook in into the Bold"Updating" event of the Object Datasource and Pass in the params in the order that you want. There is no way of actually re-ording the parameters in the InputParameters collection, so you need to copy them out then put them back in the order that you want.

The following code demostrates my implementation of this:-

void odsUsers_Updating(object sender, ObjectDataSourceMethodEventArgs e)
{
System.Collections.Specialized.ListDictionary prms = new System.Collections.Specialized.ListDictionary();
prms.Add("UserName", e.InputParameters["UserName"]);
prms.Add("email", e.InputParameters["Email"]);
prms.Add("isApproved", e.InputParameters["isApproved"]);
prms.Add("Comment", e.InputParameters["Comment"]);
prms.Add("LastActivityDate", e.InputParameters["LastActivityDate"]);
prms.Add("lastLogindate", e.InputParameters["LastLoginDate"]);
e.InputParameters.Clear();
foreach (DictionaryEntry de in prms)
{
    e.InputParameters.Add(de.Key, de.Value);
}
}
kick it on DotNetKicks.com del.icio.us digg Mister Wong YahooMyWeb Reddit Furl Spurl blogmarks
Greg Duffield Skype
Author : Greg Duffield
Published : Thursday, 26 July, 2007

Greg has too many years experience in developement from VB for DOS all the way through to Windows Workflow and LINQ while covering pretty much every technology in between. A complete MS evangelist he is now Director of the only MS Gold Partner IT services company in Norfolk. Wehere they are producing Web 2 Applications for various sectors, and are currently entering the Haulage industry with their latest product.

Add Comment

Enter your comment below and it will be submitted for moderation.

Your Name

Add Tag

Please enter tags for this article, seperated by semi-colon ;

View Tag's by : # articles | # views