News & Resources

rss feed


 

Telerik GridView Error "An item with the same key has already been added."

Posted by Stephen Sobieski on 17 Nov 2009
Earlier today I received the error "An item with the same key has already been added." while attempting to access a GridView that worked perfectly in Telerik v 2008.3 1125. I needed to upgrade to 2009.03 1103 to take advantage of some bug fixes in RadScheduler's RecurrenceRule. So, I had to identify the cause of the error.

After searching around the Telerik site I didn't find an answer. So, after some trial an error, I found the offending code that no longer works:

<telerik:GridHyperLinkColumn
    UniqueName="colSampleColumn"
    DataNavigateUrlFields="field_one,field_two,field_two"
    DataNavigateUrlFormatString="~/foo.aspx?a={0}&b={1}&c={2}"
    HeaderText="sample Column"
    AllowFiltering="true"
    SortExpression="sample_column"
    DataType="System.String"
    DataTextField="sample_column">
</telerik:GridHyperLinkColumn>

For your benefit I have highlighted the problem. Whereas v 2008.3 1125 did not care if you listed the same column twice, v 2009.03 1103 does.

Here is the correct version:

<telerik:GridHyperLinkColumn
    UniqueName="colSampleColumn"
    DataNavigateUrlFields="field_one,field_two"
    DataNavigateUrlFormatString="~/foo.aspx?a={0}&b={1}&c={1}"
    HeaderText="sample Column"
    AllowFiltering="true"
    SortExpression="sample_column"
    DataType="System.String"
    DataTextField="sample_column">
</telerik:GridHyperLinkColumn>


280 Mill Street Suite A
Rochester, Michigan 48307