Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
310
Grid Shows Duplicate Rows Until Next Postback
posted

I have a WebDataGrid that is initially empty. The user will choose a State from one dropdown list, then the next list is populated with the appropriate Counties, then they click a button to add that State and County to the database and therefore to the grid. My problem is this:

When the user adds the first row everything is perfect. When the user adds the second row, the grid displays the second row identical to the first (so it appears that the first row has been added twice), but in the database the information is actually correct. Then when they add the third row, the first and second row are displayed correctly, but now the third row is being displayed identical to the first. So each time a postback happens, the most recently added row is being shown as a duplicate of the first row.

What could be causing this to happen?

Here is my grid:

<asp:SqlDataSource runat="server" ID="SDSAIOStatesCounties" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM ProspectStateCounties WHERE ProspectID=0" />

<ig:WebDataGrid EnableViewState="false" Width="360px" Height="200px" runat="server" ID="WDGAIOStatesCounties" DataSourceID="SDSAIOStatesCounties" AutoGenerateColumns="false">

<Columns>

<ig:BoundDataField DataFieldName="ID" Key="ID" Hidden="true">

<Header Text="ID" />

</ig:BoundDataField>

<ig:TemplateDataField Key="Options" Width="50px">

<Header Text="Options" />

<ItemTemplate>

<asp:ImageButton runat="server" ImageUrl="~/icons/trash_24.png" ToolTip="Delete" CommandName="Delete" CommandArgument='<%# Eval("ID") %>' />

</ItemTemplate>

</ig:TemplateDataField>

<ig:TemplateDataField Key="State">

<Header Text="State" />

<ItemTemplate>

<%# Master.StateID2Name(Eval("StateID")) %>

</ItemTemplate>

</ig:TemplateDataField>

<ig:TemplateDataField Key="County">

<Header Text="County" />

<ItemTemplate>

<%# Master.CountyID2Name(Eval("CountyID"), Eval("StateID"))%>

</ItemTemplate>

</ig:TemplateDataField>

<ig:BoundCheckBoxField DataFieldName="PrimaryEntry" Key="PrimaryEntry" Width="60px">

<Header Text="Primary" />

</ig:BoundCheckBoxField>

</Columns>

</ig:WebDataGrid>

 

and here is the Button_Click event that inserts the row into the database and databinds the grid:

Protected Sub iBTNAIOSaveStateCounty_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles iBTNAIOSaveStateCounty.Click

Master.AddProspectStateCounty(0, DDLAIOStates.SelectedValue, DDLAIOCounties.SelectedValue, CBAIOPrimary.Checked)

DDLAIOCounties.Items.Add(New ListItem("Pick a County", "0"))

SDSAIOStatesCounties.DataBind()

WDGAIOStatesCounties.DataBind()

End Sub

Parents
No Data
Reply Children
No Data