Drag and dropped items does not show up on dynamically created listbox

2 posts, 0 answers
  1. burak
    burak avatar
    3 posts
    Member since:
    May 2009

    Posted 28 Feb 2013 Link to this post

    Hi guys,

    I'm having a problem with the drag and drop functionality of the radlistbox.

    In my scenario i need to create dynamic controls depending to the data coming from the database. When I drag and drop an item from static listbox to the listboxes dynamically created, items does not show up until some other control other than listbox forces an autopostback. I have tried setting autopostbackaftertransfer  to true but still the same result. I can see that item dropped event on the server side is triggering and all the items I previously dropped to the listbox is available within the listbox's item collection thou not visible until another control forces a postback. Any ideas what could be causing the problem?

    protected void Page_Load(object sender, EventArgs e)
        {        
            if (Page.IsPostBack)
            {
                 //generate forms again using existing variables
                 GenerateSlotForms();          
            }
            else
            {  
                 //get some initial variables from querystring
                GenerateSlotForms();
            }
     
    }
     
     protected void GenerateSlotForms()
            {
                 
                    divSlot.Visible = true;
                    int tblRows, tblCols;
                    DataView dvCorpSlot;
                    dvCorpSlot = (DataView)CorpSlot.Select(DataSourceSelectArguments.Empty);  //corporation lists
                     
                    
                    if (RadNumericTextBox5.Value == 1)
                    {
                        tblRows = 1;
                        tblCols = 1;
                    }
                    else
                    {
                        tblRows = (Convert.ToInt16(dvCorpSlot.Count) / 2) + (Convert.ToInt16(dvCorpSlot.Count) % 2);
                        tblCols = 3;
                    }
     
                    int k = 0;
     
                    for (int i = 0; i < tblRows; i++)
                    {
                        TableRow tr = new TableRow();
                        for (int j = 0; j < tblCols; j++)
                        {
                            PlaceHolder1.Controls.Add(tr);
     
                            TableCell tc = new TableCell();
     
                            if ((i * 3) + j + 1 <= Convert.ToInt16(dvCorpSlot.Count))
                            {
                           
                                tc.Controls.Add(CreateControlSlotListBox(k));
                              
                                tr.Cells.Add(tc);
     
                                k++;
                            }
                        }
     
                        tbl.Rows.Add(tr);
                }
            }    
         private Control CreateControlSlotListBox(int i)
            {
                ListBox SlotListBox = new ListBox();
                SlotListBox.ID = "SlotListBox" + i;
                SlotListBox.Width = 190;
                
                return SlotListBox;
            }

        protected void RadListBox_Dropped(object sender, RadListBoxDroppedEventArgs e)
            {
                foreach (RadListBoxItem item in e.SourceDragItems)
                {
                    string controlname = e.HtmlElementID;
                    if (controlname.Contains("Skinned")) { controlname = controlname.Substring(7); }
                    ListBox slotListBox = (ListBox)Page.FindControl(controlname);
                    slotListBox.Items.Add(item.Text);
                    slotListBox.Items.FindByText(item.Text).Value = item.Value;

                }

    <div id="divSlot" runat="server" visible="false">

    <
    telerik:RadListBox ID="RadListBox1" runat="server" EnableDragAndDrop="true" SelectionMode="Multiple"
    AllowTransferDuplicates="True" DataKeyField="Descr" OnDropped="RadListBox_Dropped" Height="250"
    D
    ataSourceID="PPIEEmployeeListAll" DataTextField="Descr" DataValueField="Expr1">                  </telerik:RadListBox>

    <
    asp:PlaceHolder ID="PlaceHolder1" runat="server" EnableViewState="false"></asp:PlaceHolder>
    /div>



  2. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 05 Mar 2013 Link to this post

    Hello Burak,

    Could you elaborate a bit more on the scenario you attempt to achieve. How do you associate the newly created control with the ListBox you need to allow transferring? In addition, please keep in mind that Dropped event will not be fired, when you drop an item over another RadListBox/RadListBoxItem.

    Greetings,
    Nencho
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top