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

can't insert item into ddl in grid

3 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
eric
Top achievements
Rank 1
eric asked on 10 Dec 2009, 01:16 AM
I have a radgrid that uses a usercontrol as its edit form and in that user control i have a few drop down lists.  In the usercontrol I try to insert a list item into one of my ddl's after it is databound and it adds successfully.  When the prerender event fires for that DDL the inserted item disappears.  I double checked to make sure the DDL was not getting rebound which it was not.  I've noticed this before and my work around is to insert the item in the ddl prerender function and then everything works fine.  I only have this issue with dropdowns that are in grid user control edit forms.  Any thoughts?

3 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 10 Dec 2009, 03:29 PM
Hi eric,

The only scenario that I can think of is when the ddl is rebound and its items are cleared before rebinding. Other than that, the inserted item should stay. In any case, PreRender is a safe place to manually insert additional items after binding your ddl, so I would stick to this approach.

Kind regards,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
eric
Top achievements
Rank 1
answered on 10 Dec 2009, 08:31 PM
The prerender method does work fine but it makes for sphagetti code because you end up adding items later than would really be logical.  I talked to two other co workers and they both have encountered this issue.  One of them said that they just dont bind any data to the ddl in this case and they just have a for loop insert the items into the ddl.  This isn't a major issue but there is definitly something going on here.  Thanks for your reply Veli.
0
Veli
Telerik team
answered on 11 Dec 2009, 08:23 AM
Hello eric,

I agree with you that using PreRender in this case would be a potential spaghetti code introducer. How about attaching to the DataBound event of the DropDownList? In this case, you will make sure that you  add your additional items only after the DDL has been bound, and you will ensure your items will not be cleared as a result of the binding.


Best wishes,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
eric
Top achievements
Rank 1
Answers by
Veli
Telerik team
eric
Top achievements
Rank 1
Share this question
or