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?
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"
DataSourceID="PPIEEmployeeListAll" DataTextField="Descr" DataValueField="Expr1"> </telerik:RadListBox>
<asp:PlaceHolder ID="PlaceHolder1" runat="server" EnableViewState="false"></asp:PlaceHolder>
/div>