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

Selected ListBox items are not shown

1 Answer 60 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 2
Dan asked on 30 Jul 2013, 05:46 PM
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;
           }
       }

1 Answer, 1 is accepted

Sort by
0
Dan
Top achievements
Rank 2
answered on 30 Jul 2013, 06:27 PM
Never mind.  I fixed it by moving the RadListBox selection logic to the FormView OnDataBound method.

Dan
Tags
ListBox
Asked by
Dan
Top achievements
Rank 2
Answers by
Dan
Top achievements
Rank 2
Share this question
or