RadListBox

12 posts, 0 answers
  1. Lance
    Lance avatar
    2 posts
    Member since:
    Nov 2010

    Posted 23 Nov 2010 Link to this post

    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.
  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 24 Nov 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Lance
    Lance avatar
    2 posts
    Member since:
    Nov 2010

    Posted 25 Nov 2010 Link to this post

    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.
  5. prabha
    prabha avatar
    22 posts
    Member since:
    Nov 2010

    Posted 26 Nov 2010 Link to this post

    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
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Nov 2010 Link to this post

    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.
  7. prabha
    prabha avatar
    22 posts
    Member since:
    Nov 2010

    Posted 29 Nov 2010 Link to this post

    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
  8. Alastair Hole
    Alastair Hole avatar
    4 posts
    Member since:
    Feb 2009

    Posted 10 Jan 2011 Link to this post

    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
  9. Francis Frank
    Francis Frank avatar
    35 posts
    Member since:
    Mar 2010

    Posted 02 Apr 2013 Link to this post

    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();
    }
  10. Bozhidar
    Admin
    Bozhidar avatar
    1101 posts

    Posted 03 Apr 2013 Link to this post

    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.
  11. Francis Frank
    Francis Frank avatar
    35 posts
    Member since:
    Mar 2010

    Posted 03 Apr 2013 Link to this post

    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.
  12. Bozhidar
    Admin
    Bozhidar avatar
    1101 posts

    Posted 04 Apr 2013 Link to this post

    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.
  13. Phanindra
    Phanindra avatar
    3 posts
    Member since:
    Oct 2013

    Posted 01 Aug 2014 in reply to Lance Link to this post

    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

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017