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

Re-Binding Radlistbox without postback

3 Answers 268 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Dwayne Moore
Top achievements
Rank 1
Dwayne Moore asked on 01 Apr 2010, 09:50 PM

I have a 2 list boxes on a page the master list box is loaded from code behind.   I have a second list box on the page which I want populated dynamically.  I have a sqldatasource which calls an parameterized sql strored procedure to load the data.  The control parameter is tied to a text box on the page.  Each time a item or series of items are selected from my first radio list, it populates the textbox with the item values and that in turn should call the sproc with the values as a parameter to load into the second  list box.  It works in theory J, but I’m having a problem loading my second list box.  I really don’t want to have the form post back, because it’s not very optimized even with the ajax controls that can give the same effect as it not posting back.  Any help would be greatly appreciated.

Below is an example of the scenario that I have.

 

<telerik:RadTextBox ID="txtMerch" runat="server" Visible="true"> </telerik:RadTextBox>

           

            <telerik:RadListBox ID="RadListBox1" runat="server" Height="200px" Skin="Forest"                            CheckBoxes="true" Width="200px" AutoPostBack="false" OnClientItemChecked="onItemChecked" OnClientItemChecking="onItemChecking" >

            </telerik:RadListBox>

            <telerik:RadListBox ID="RadListBox2" runat="server" DataSourceID="SqlDataSource2" 

              DataKeyField="mykey" DataTextField="Locations"  Height="200px" Skin="Forest" AllowAutomaticUpdates="true" AutoPostBack="false"

            CheckBoxes="true" Width="200px">

            </telerik:RadListBox>

            <asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:MyConnectstring %>"

        runat="server"  

           

            SelectCommand= "[dbo].[RptMgr_GetLocations]"

           

            ProviderName="<%$ ConnectionStrings:MyConnectstring.ProviderName %>"

            SelectCommandType="StoredProcedure" DataSourceMode="DataReader">

        <SelectParameters>

<asp:ControlParameter ControlID="txtMerch"  Name="merch"

PropertyName="Text" Type="String"  />

            <asp:Parameter Direction="ReturnValue" Name="RETURN_VALUE" Type="Int32" />

        </SelectParameters>

    </asp:SqlDataSource>

3 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 02 Apr 2010, 09:42 AM
Hello Dwayne Moore,

RadListBox does not support client-side binding via WebServices/PageMethods out of the box. This means that you cannot bind it on the client and a postback is required. The same applies to SqlDataSource. It is tightly connected with the ASP.NET postbacks paradigm and you can hardly use it in other scenario.

A possible way to overcome this issue is enlisted below:

1) Create WebService that returns the data you need in JSON format.
2) Parse the JSON on the client
3) Create RadListBoxItems that utilize the received data
4) Add the newly created items to the listbox.

Items can be created on the client the following way:

var item = new Telerik.Web.UI.RadListBoxItem();
item.set_text('some text');
item.set_value('some value');
 
$find("RadListBox1").get_items().add(item);


Greetings,
Genady Sergeev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Collin
Top achievements
Rank 1
answered on 28 Jun 2011, 07:35 PM
I actually did an experiment doing this, here is my code-

http://trappedinhoth.blogspot.com/2011/06/populating-telerik-radlistbox-with-json.html

A lot left to be desired, but it works, and is enough to get you going.
0
Genady Sergeev
Telerik team
answered on 01 Jul 2011, 12:19 PM
Hello Collin,

Thank you for sharing this approach with the community. I've updated your telerik points as token of gratitude for the involvement.

Best wishes,
Genady Sergeev
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
ListBox
Asked by
Dwayne Moore
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Collin
Top achievements
Rank 1
Share this question
or