Exception "Object must implement IConvertible" for multiple-field DataKeyNames in a GridView




I've been using a GridView for some time but this is the first time I need
to delete a row in the grid whose primary key consists of 2 fields (table
columns). I have a table with primary key set to c1,c2 where c1 is a
uniqueidentifier and c2 is int.

The DataKeyNames in the gridview is defined as follows:

I have a ObjectDataSource defined with following delete params:
<asp:parameter Name="c1", Type="String" />
<asp:parameter Name="c2" Type="Inte32" />

The ods is mapped to a bll's method Delete(string, int). Unfortunately the
method never gets called.

I attached RowDeleting event handler to the gridview to see the content of
GridViewDeleteArgs.Keys. The dictionary looks fine there, including key
names and values.

Partial stack dump of the exception that I get afterwards:

[InvalidCastException: Object must implement IConvertible.]
System.Convert.ChangeType(Object value, TypeCode typeCode,
IFormatProvider provider) +2561730
System.Web.UI.WebControls.Parameter.GetValue(Object value, String
defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean
ignoreNullableTypeChanges) +264
reference, IDictionary source, IDictionary destination, String
parameterNameFormatString) +439
keys, IDictionary oldValues) +846
System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary
oldValues, DataSourceViewOperationCallback callback) +75

Could someone please let me know how to troubleshoot this?


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question