Monday, March 26, 2012

Duplicate Items in dropdownlist inside an Updatepanel

Hi,

I have been working with Atlas for the past couple of weeks and I have a very simple page with a dropdownlist box inside a updatepanel. I have a button that inserts a value in the back-end database and refresh the dropdownlist. This button is also a trigger for the updatepanel. This dropdownlist is bounded to an ObjectDataSource.

The problem is that on the first click, the values in the dropdownlist are duplicated with the original list and plus the new value. So I have the original list show up twice and the new value at the end. However, on the second click, the dropdownlist is updated correctly with only the new value being appended at the end. Doesn't anyone have the same problem?

ThanksSmile

<atlas:UpdatePanelID="UpdatePanelReason"runat="server"Mode="Conditional">

<ContentTemplate>

<asp:DropDownListID="drpReason"runat="server"AppendDataBoundItems="True"DataSourceID="ObjectDataSource1"DataTextField="ITEM_SUB_TYPE_NAME"DataValueField="PK_ITEM_SUB_TYPE_ID">

<asp:ListItemValue="0">Select Reason</asp:ListItem>

</asp:DropDownList>

</ContentTemplate>

<Triggers>

<atlas:ControlEventTriggerControlID="btnAddReason"EventName="Click"/>

</Triggers>

</atlas:UpdatePanel>

My post-back method to insert a new value in the dropdownlist.

ProtectedSub btnAddReason_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles btnAddReason.Click

IfMe.txtNewReason.Text <>String.EmptyThen

Dim lookupMgrAsNew LookupManager

lookupMgr.insertItemSubType(Me.txtNewReason.Text, Session("ItemType"))

Me.drpReason.DataBind()

EndIf

EndSub

Problem solved!! All I have to do is clear all the items in the dropdownlist before calling databinding.

:)

No comments:

Post a Comment