HighTechTalks DotNet Forums  

DataKeyName GridView has already been added

ASP.net Data Grid Control microsoft.public.dotnet.framework.aspnet.datagridcontrol


Discuss DataKeyName GridView has already been added in the ASP.net Data Grid Control forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Marco Liedekerken
 
Posts: n/a

Default DataKeyName GridView has already been added - 11-07-2006 , 09:39 AM






Hi,

I get an error which says:
Item has already been added. Key in dictionary: 'MutaP_StartDate' Key
being added: 'MutaP_StartDate'

I have a master page and in its content page I have a usercontrol with
in that 3 usercontrols as tabs.
In one of the 3 user controls I have a GridView defined (see my code
down under). I bind this GridView via DataSourceID to a SqlDataSource
(see my code down under). In my code behind of this user control I have
a method that fills other subcontrols which are on it (the GridView
will automaticly be filled).

My problem is that when I click on a edit button (or do deleting,
sorting ....) of the Gridview I get the error message.

I think it has to do with viewstate or something (I tried a lot of
combinations allready), but I can not put a finger on this problem. It
seems that it tries 2 times to add the DataKey which I put in as
DataKeyNames of the GridView. Maybe this is because of a problem with
databinding ...

Can someone help me with this, because I am puzzled?

Thx, Marco


<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlDataSourceParameterMutaties"
AutoGenerateEditButton="true" DataKeyNames="MutaP_StartDate"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField HeaderText="StartDatum"
DataField="MutaP_StartDate" ReadOnly="true" />
<asp:BoundField HeaderText="Waarde"
DataField="MutaP_Value" />
<asp:BoundField HeaderText="Omschrijving "
DataField="MutaP_Description" />
<asp:BoundField HeaderText="Gewijzigd"
DataField="MutaP_ChangeTime" ReadOnly="true"/>
</Columns>
</asp:GridView>


<asp:SqlDataSource ID="SqlDataSourceParameterMutaties"
runat="server" ConnectionString="<%$ ConnectionStrings:SSSDemo %>"
SelectCommand="SELECT MutaP_StartDate, MutaP_Value,
MutaP_Description, MutaP_ChangeTime FROM dbo.SSS_TMutaties_parameters
WHERE (MutaP_Varia_ID = @MutaP_Varia_ID) AND (MutaP_Param_ID =
@MutaP_Param_ID) ORDER BY MutaP_StartDate"
UpdateCommand="UPDATE dbo.SSS_TMutaties_parameters SET MutaP_Value
= @MutaP_Value, MutaP_Description = @MutaP_Description,
MutaP_ChangeTime = GETDATE() WHERE (MutaP_Varia_ID = @MutaP_Varia_ID)
AND (MutaP_Param_ID = @MutaP_Param_ID) AND (MutaP_StartDate =
@MutaP_StartDate)" >
<SelectParameters>
<asp:QueryStringParameter
Name="MutaP_Varia_ID"
QueryStringField="VariantID"
Type="Int32" />
<asp:QueryStringParameter
Name="MutaP_Param_ID"
QueryStringField="ParameterID"
Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:QueryStringParameter
Name="MutaP_Varia_ID"
QueryStringField="VariantID"
Type="Int32" />
<asp:QueryStringParameter
Name="MutaP_Param_ID"
QueryStringField="ParameterID"
Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.