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

[Solved] Dynamically created DropDownList loses values

3 Answers 222 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Digital Man asked on 04 May 2009, 02:43 PM
I'm creating controls dynamically in the ItemCreated event of my grid. I'm adding these controls to my edit form (WebUserControl) for insert/update. All my textbox type controls work fine but my dropdown control seems to lose its items after postback. How can I get it to keep it values/viewstate after postback? Thanks.


        protected void rgData_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
            {
                UserControl edit = e.Item.FindControl(GridEditFormItem.EditFormUserControlID) as UserControl;
                ..........................................
                        switch (type)
                        {
                            case CustomFieldTypeController.CustumFieldTypeEnum.Boolean:
                                c = new DropDownList();
                                ((DropDownList)c).Items.Add(new ListItem("--Select--", ""));
                                ((DropDownList)c).Items.Add(new ListItem("true", "true"));
                                ((DropDownList)c).Items.Add(new ListItem("false", "false"));

                                break;



3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 May 2009, 07:03 AM
Hi Dan,

Can you confirm whether the dropdown values are getting lost on a normal post back or on clicking the edit button of other row? I have found a forum link which discusses a similar issue. Just go through it and see if it helps.
Dynamically created DropDownList loses ListItems on Postback

Shinu
0
answered on 05 May 2009, 02:53 PM
Sorry, you may be right. It had the behavior of not saving the ListItems but now it seems something else may be the problem.
0
answered on 05 May 2009, 03:23 PM
Yep, I made an @$$ our of myself by @$$uming what the problem was. Sorry for the post. :-)

Was just some bad update logic that made it appear like what I was describing.
Tags
Grid
Asked by
Answers by
Shinu
Top achievements
Rank 2
Share this question
or