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

[Solved] Listbox on edit form - cannot select item

2 Answers 144 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John Davis
Top achievements
Rank 2
John Davis asked on 26 Jun 2008, 01:06 AM

I have a listbox on a user control that serves as an edit control for a radgrid that is on another user control.

Everything executes without error but when the listbox displays it has nothing selected.
Here is the aspx and code behind.

private void UsersControlEditSCS_DataBinding(object sender, System.EventArgs e)
    {

        listSCS.DataBind();
        listSCS.Items[i].Selected = true;
        listSCS.Items[0].Selected = true;
        listSCS.Items[1].Selected = true;
        listSCS.Items[2].Selected = true;
        }
    }

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UsersControlEditSCS.ascx.cs" Inherits="BalancedFlow.WebSite3._5.Controls.UsersControlEditSCS" %>
<table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="1" rules="none"
 style="border-collapse: collapse">
 <tr>
  <td colspan="2">
   <b>Link to SCS</b></td>
 </tr>
 <tr>
  <td colspan="2">
  
   (Select one, or more with CTRL key)</td>
 </tr>
 <tr>
  <td>
   <table id="Table3" cellspacing="1" cellpadding="1" width="100%" border="0">
 
   </table>
  </td>
  <td>
   <table id="Table1" cellspacing="1" cellpadding="1" width="300" border="0">
    <tr>
     <td>
      &nbsp;</td>
    </tr>
    <tr>
     <td>
      <asp:ListBox ID="listSCS" runat="server" SelectionMode="Multiple" DataTextField="SCS_Name"
       DataValueField="SCS_ID" Width="325px"></asp:ListBox>
     </td>
    </tr>
    <tr>
     <td>
      &nbsp;</td>
    </tr>
    <tr>
     <td>
      &nbsp;</td>
    </tr>
   </table>
  </td>
 </tr>
 <tr>

2 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 30 Jun 2008, 09:34 AM
Hi John Davis,

Could you please try setting the selected items of the listbox in the ItemDataBound event of RadGrid in the following way:

void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
    { 
        GridEditFormItem item = (GridEditFormItem)e.Item; 
        (item.FindControl("listSCS"as ListBox).Items[1].Selected = true
    } 

Greetings,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
John Davis
Top achievements
Rank 2
answered on 01 Jul 2008, 12:14 PM
Thank you. Yes it works when you set the selected items of the listbox in the ItemDataBound event of RadGrid.  (My code must be a little different from your example because I use a user control for editing.)

John
Tags
Grid
Asked by
John Davis
Top achievements
Rank 2
Answers by
Veli
Telerik team
John Davis
Top achievements
Rank 2
Share this question
or