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

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

1 Answer 59 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
burak
Top achievements
Rank 1
burak asked on 28 Feb 2013, 03:54 PM
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>



1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 05 Mar 2013, 01:34 PM
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.
Tags
ListBox
Asked by
burak
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or