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

RadListBox

11 Answers 390 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Lance
Top achievements
Rank 1
Lance asked on 23 Nov 2010, 09:17 AM
I have avoided your product for a long time and now I feal justified in that decisision. Unfortunatley I am now working for a shop that uses Telerik controls. Not only are they difficult to use but in a lot of cases they do not even have the normal ASP expected behaviour. I have lost two days trying to get the selected item value form a RadListBox inside a RadAjaxPanel code as below, simple really, the event "test" on the code behind fires but the sender has no selected value. I suspect it is more the AjaxPanel than the Listbox causing the problem.

When I use client side code it works fine, but thats not what I want, I just want to get the value selected when an item is selected.

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
         <telerik:RadListBox ID="lstTRBStandard" 
                                        DataTextField="SubjectAreaName"
                                        DataValueField="SubjectAreaId"
                                        Height="350px"
                                        Width="240px"
                                        runat="server"
                                        OnClientSelectedIndexChanged="test"
                                        AutoPostBack="true" >
                                    </telerik:RadListBox>
</telerik:RadAjaxPanel>

Can someone please show me how this can work.

11 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 24 Nov 2010, 01:27 PM
Hi Lance,

On the server, you can access the selected value using the SelectedValue property that RadListBox provides. There are no known issues with RadListBox in RadAjaxPanel. What is your exact scenario?

I've tested that using the following markup and code and it seems to work fine:

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
 
        <telerik:RadListBox runat="server" Height="300px" Width="250px" ID="RadListBox1" AutoPostBack="true">
           <Items>
               <telerik:RadListBoxItem Text="Text1" Value="Text1" />
               <telerik:RadListBoxItem Text="Text2" Value="Text2" />
               <telerik:RadListBoxItem Text="Text3" Value="Text3" />
               <telerik:RadListBoxItem Text="Text4" Value="Text4" />
               <telerik:RadListBoxItem Text="Text5" Value="Text5" />
           </Items>
       </telerik:RadListBox>
 
       <asp:Label runat="server" ID="Label1"></asp:Label>
 
   </telerik:RadAjaxPanel>

protected void Page_Load(object sender, EventArgs e)
  {
      RadListBox1.SelectedIndexChanged += new EventHandler(RadListBox1_SelectedIndexChanged);
      
  }
 
  void RadListBox1_SelectedIndexChanged(object sender, EventArgs e)
  {
      Label1.Text = RadListBox1.SelectedValue;
  }

Can you test this code on your side?

Best wishes,
Genady Sergeev
the Telerik team
Browse the vast support resources we have to jumpstart 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.
0
Lance
Top achievements
Rank 1
answered on 26 Nov 2010, 02:57 AM
First of all, the code you used as an example gives me the following message

Literal content ('<telerik:RadListBoxItemText="Text1"Value="Text1"/>
               <telerik:RadListBoxItemText="Text2"Value="Text2"/>
               <telerik:RadListBoxItemText="Text3"Value="Text3"/>
               <telerik:RadListBoxItemText="Text4"Value="Text4"/>
               <telerik:RadListBoxItemText="Text5"Value="Text5"/>') is not allowed within a 'Telerik.Web.UI.RadListBoxItemCollection'.   at System.Web.UI.CollectionBuilder.AppendLiteralString(String s)
   at System.Web.UI.TemplateParser.ProcessLiteral()


Secondly in a perfect world we would know everything in advance and we could hard code everything in our applications. However as you will see from the example I posted previously I am using a bound data source, hence the two fields  DataTextField="SubjectAreaName"  and  DataValueField="SubjectAreaId".
 
I managed to get is working by iterating through each item in the datasource and adding them individually i.e. new RadListBoxItem(string, string), So it is obvious to me that there is a problem with databinding and returning a selected item. Pretty poor that I cant bind a dtatsource and have to go to the trouble of populating the list in code.

The issue was that the selected item returned a null value when using a bound datasource.
0
prabha
Top achievements
Rank 1
answered on 26 Nov 2010, 07:28 AM
Hi ,
 How to get the Radlistbox checked checkbox id in the server side  from the ItemChecked event ?
I can get RadListBox1.CheckedITems,But i want the currently checked item only
0
Princy
Top achievements
Rank 2
answered on 26 Nov 2010, 10:55 AM
Hello Prabha,

If you want to access the currently checked item ,you can easily access it by the following code.

C#:
protected void RadListBox1_ItemCheck(object sender, Telerik.Web.UI.RadListBoxItemEventArgs e)
  {
      RadListBoxItem item=(RadListBoxItem)e.Item;
      string a=item.Text;
  }

Thanks,
Princy.
0
prabha
Top achievements
Rank 1
answered on 29 Nov 2010, 11:03 AM
Thank you very much .I have another issue with rad listbox.
RadListbox Without scrolling ,it works well .
when i scroll the RadListbox and did some post back operation .Than the Page is flickered .
Please give me suggestion.

Thanks
Prabha
0
Alastair Hole
Top achievements
Rank 1
answered on 10 Jan 2011, 04:55 PM
FYI, when databinding the radlistbox, make sure you bind ONLY when !Page.IsPostBack
If you databind on every page load, you will see the SelectedValue == null type behaviour when handling SelectedIndexChanged
0
Francis Frank
Top achievements
Rank 1
answered on 02 Apr 2013, 04:15 PM
Please i have an urgent need here
My support ticket had just expired and am trying to get the management to approved the renewal

but here is the issue:
I have a tooltip with a RadListBox loaded from the database as shown below.
but when the user checks the checkboxes, i can not retrieve the value from the RadListBox because the RadListBox is databounded again at PageLoad.
I tried using OnItemClick which captured the checked value but it unchecks it once the page refreshes.

(summary) Please i need a way to get all the checked items on the RadListBox that is databound.

Thanks
                                     
                              <telerik:RadListBox ID="chkBoxCircle" runat="server"
    CheckBoxes="True" AutoPostBack="True" DataTextField="TITLE" DataValueField="CIRCLE_ID" OnItemCheck="chkBoxCircle_ItemCheck" >
</telerik:RadListBox>
Code Behind:

  protected void Page_Load(object sender, EventArgs e)
    {
        DataTable PersonData = null;
PersonData = SelectRequestInfo(string.Format("SELECT Circle_Info.TITLE, Circle_Info.CIRCLE_ID FROM Circle INNER JOIN Circle_Info ON Circle.CIRCLE_ID = Circle_Info.CIRCLE_ID WHERE (Circle.CREATOR_ID = '{0}')", PersonID));
            chkBoxCircle.DataSource = PersonData;
            chkBoxCircle.DataBind();
}
0
Bozhidar
Telerik team
answered on 03 Apr 2013, 07:40 AM
Hi Francis,

As Alastair said in the last post here, you have to enclose the binding in an if(!Page.IsPostBack) block. For example:
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        RadListBox1.DataSource = new List<string>() { "item 1", "item 2", "item 3" };
        RadListBox1.DataBind();
    }
}

 

Greetings,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Francis Frank
Top achievements
Rank 1
answered on 03 Apr 2013, 08:02 AM
I tried to enclose the binding but when the page reloads, the radlistbox will become empty with no item.\
So its not able to retain its items once they are bounded at runtime.
0
Bozhidar
Telerik team
answered on 04 Apr 2013, 08:51 AM
Hello Francis,

Could you open a support ticket and attach a runnable sample project filled with dummy data that reproduces the issue, so that we can troubleshoot it locally.
 

Greetings,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Phanindra
Top achievements
Rank 1
answered on 01 Aug 2014, 11:01 AM
Hai Lance

Instead of datavaluefield use DataKeyField. for example
listview1.DataKeyField="ID";
listview1.DataTextField="Name";
listview1.DataSource=list;
listview1.DataBind();
 then you will get the ids using lisview1.selectedvalue

Tags
ListBox
Asked by
Lance
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Lance
Top achievements
Rank 1
prabha
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Alastair Hole
Top achievements
Rank 1
Francis Frank
Top achievements
Rank 1
Bozhidar
Telerik team
Phanindra
Top achievements
Rank 1
Share this question
or