This is a migrated thread and some comments may be shown as answers.

Radajax manager update or refresh the dropdownlist

1 Answer 252 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Phani
Top achievements
Rank 1
Phani asked on 03 Mar 2014, 09:06 PM
I have an asp.net drop down list. There is a "new" option in it. Selecting that will show 2 labels,2 text boxes and an asp.net button. Entering values in the textboxes("John","Doe")and hitting the button should add a value to the Database table and also refresh this drop down and . It did that when I DID NOT use ajax. Now when i use ajax (radajaxmanager), it adds the value to the table and shows that it is selecting the newly added value in the codebehind, but the drop down selected value shows as "New". It should say for example "John Doe". I went for ajax because I have many drop downs in the page and postbacks were not optimal.  Where did I go wrong?

<telerik:RadAjaxManager ID="ram" runat="server"><br>        <AjaxSettings><br>            <telerik:AjaxSetting AjaxControlID="ddlCustomerContact"><br>                <UpdatedControls><br>                    <telerik:AjaxUpdatedControl ControlID="divAddNewCustomerContact"/><br>                </UpdatedControls>
 </telerik:AjaxSetting>
</AjaxSettings>
        </telerik:RadAjaxManager>

In the codebehind  I write a method BindCustomerContact() after I add "John Doe". 

 If intNewCustomerID > 0 Then<br>            ddlCustomerContact.SelectedValue = intNewCustomerID<br>        Else<br>            ddlCustomerContact.SelectedIndex = 0<br>        End If<br>...

When I debugged it set the value of the drop down as the new value, but my UI shows "New". Any help would be appreciated.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Mar 2014, 06:44 AM
Hi Phani,

Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
     <AjaxSettings>
         <telerik:AjaxSetting AjaxControlID="DropDownList1">
             <UpdatedControls>
                 <telerik:AjaxUpdatedControl ControlID="Panel1" />
             </UpdatedControls>
         </telerik:AjaxSetting>
         <telerik:AjaxSetting AjaxControlID="Panel1">
             <UpdatedControls>
                 <telerik:AjaxUpdatedControl ControlID="DropDownList1" />
             </UpdatedControls>
         </telerik:AjaxSetting>
     </AjaxSettings>
 </telerik:RadAjaxManager>
 <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"                DataValueField="CountryName" AutoPostBack="true" DataTextField="Cityname"                      OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
 </asp:DropDownList>
 <asp:Panel ID="Panel1" runat="server" Visible="false">
     <asp:Label ID="Label1" runat="server" Text="CityName">
     </asp:Label>
     <asp:TextBox ID="TextBox1" runat="server">
     </asp:TextBox>
     <br />
     <asp:Label ID="Label2" runat="server" Text="CountryName">
     </asp:Label>
     <asp:TextBox ID="TextBox2" runat="server">
     </asp:TextBox>
     <br />
     <asp:Button ID="Button1" runat="server" Text="Add Item" OnClick="Button1_Click" />
 </asp:Panel>

VB:
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
    If DropDownList1.SelectedItem.Text = "New" Then
        Panel1.Visible = True
    End If
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs)
    Try
        'your code for updating value to db
        DropDownList1.DataBind()
        Panel1.Visible = False
 
    Catch msg As Exception
    End Try
End Sub

Hope this will helps you.
Thanks,
Princy.
Tags
General Discussions
Asked by
Phani
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or