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

RadComboBoxes and DropDownLists in WebControl EditForm

4 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 12 Jun 2014, 03:30 PM
Hi.

I've developed a page with a RadGrid, sourced by a List of POCO's, using an EditFormType of WebUserControl.  My user control handles the DataBinding event (attaching to it in the control's Page_Load(), if that's important).  I click my edit button in the grid... the control pops up, mostly with populated data.  I seem to at least be doing something right...

The one input in the user control I can't seem to get populated is the drop-down, which I've tried implementing as both a plain old ASP.NET DropDownList or a RadComboBox.  If I debug and step through my DataBinding handler.  I can see that it's been properly selected.  But sometime between the end of the DataBinding() call and rendering, the list has lost its selection, and renders showing the first item in the dropdown.

The grid itself is inside a RadAjaxPanel, but I it doesn't appear to be an ajax issue because the problem persists when I set the panel's EnableAjax=false.

All I'm doing to select an item is:

public void SelectBU(string s)
{
    lstBU.ClearSelection();
    lstBU.FindItemByValue(s).Selected = true;
}

The function that databinds the list itself checks the item-count of the list, and skips the data binding if there are already items.  So it's not losing the selection due to an extra bind.

If I just throw this control on a blank page and call SelectBU() from the .aspx codebehind, it works fine.

I'm on 2014.1.225.40 in ASP.NET 4.0, and I'm targeting IE9 primarily.  (I've seen this same behavior in the versions of Chrome and Firefox I have installed on my box.)

Thanks for any guidance anyone can provide.



4 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 12 Jun 2014, 03:38 PM
Interesting...

1) If I put the SelectBU() call directly into the user control's page load, it functions the same: it works outside of the grid, but not as an edit form.

2) Just FYI: obviously, the SelectBU() has to be modified to run with a dropdownlist, because as written, that function would only compile against a RadComboBox.  In any case, I've managed to get the function to compile and work outside of the grid, but not as an edit form.
0
Accepted
Princy
Top achievements
Rank 2
answered on 13 Jun 2014, 09:17 AM
Hi John,

Please take a look at this sample demo, which shows binding of dropdownlist in editform of usercontrol. Please provide your code snippet if this doesn't help.
Edit Form Types

Thanks,
Princy
0
John
Top achievements
Rank 1
answered on 13 Jun 2014, 12:25 PM
Thanks for your reply, Princy.

I'd actually been referencing that demo, but your suggestion made me look a little closer, and I noticed this:

ddlTOC.DataSource = null;

I've never nulled out a control's datasource before, but I did this time and everything works fine now.  I presume it has something to do with the fact that the dropdown is contained within a data-bound context?

Thanks for your help.
0
Princy
Top achievements
Rank 2
answered on 18 Jun 2014, 08:19 AM
Hi John,

The reason to set the DropDownList  DataSource as null is that it will prevent binding it again at a later stage (when the  rest of the edited item content is bound). The same conventions stand for nested user controls inside WebUserControl custom
edit form or other controls such as listboxes, radiobutton lists, checkbox lists, and so on.

 
You can find this in this documentation under the heading 'Binding selected values for drop-down lists'.

Regards,
Princy.
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or