Selected ListBox items are not shown

2 posts, 0 answers
  1. Dan
    Dan avatar
    202 posts
    Member since:
    May 2006

    Posted 30 Jul 2013 Link to this post

    I have a RadListBox with multi-select turned on.  On selection of another list control, in the code-behind of the other list control, I get its value, then select records from a database, and want to select the corresponding items in the RadListBox (called "listWho" below).  When walking thru the code, it is selecting the list box items, but, after postback, the list box shows not selected items.  Why?

    Here is the code.  Any help appreciated.  Dan

    <telerik:RadListBox ID="listWho" runat="server" DataSourceID="dsScheduleWho" TabIndex="2"
    DataTextField="wholist" DataValueField="pk" Height="120px" Width="169px"
    Skin="Vista" SelectionMode="Multiple" OnClientLoad="listWho_ClientLoad">
    </telerik:RadListBox>
     
     
    protected void DistGroup_SelectedIndexChanged(object sender, EventArgs e)
    {
       string itemValue;
       DropDownList ddl = sender as DropDownList;
       string DG_cpk = ddl.SelectedValue;
     
       try
       {
           RadListBox rlb = (RadListBox)pageform.FindControl("listWho");
           DataAccess sda = new DataAccess();
           sda.RunSelectCmd("select cpk_users from users inner join DG_Users_Link DUL on users.CPK_USERS = DUL.Cfk_Users and DUL.DELFLAG=0 "
               + "inner join DistributionGroups DG on DUL.Cfk_DistributionGroups=DG.CPK_DistributionGroups and DG.delflag=0 "
               + "where users.DELFLAG=0 and DG.CPK_DistributionGroups=" + DG_cpk);
     
           if (!sda.blNoRecords)
           {
               foreach (DataRow dr in sda.dtResult.Rows)
               {
                   itemValue = dr["cpk_users"].ToString();
                   RadListBoxItem rlbi = rlb.FindItemByValue(itemValue);
                   rlbi.Selected = true;
               }
           }
  2. Dan
    Dan avatar
    202 posts
    Member since:
    May 2006

    Posted 30 Jul 2013 Link to this post

    Never mind.  I fixed it by moving the RadListBox selection logic to the FormView OnDataBound method.

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