Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problems adding item to drop down list with BindingSource
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Problems adding item to drop down list with BindingSource
Environment versions
Environment:
C# 2.0
OS:
Windows Server 2003
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01142818
Message ID:
01142818
Views:
80
I still haven't gotten the drop down lists to work correctly with multiple tables for a data set but got around that by using a reader to reference the second table and load the drop down list. When I programmatically add a blank line to the ListItem collection, that drop down (ddlapprovers) show the blank line correctly. However, when I use the same code to add a blank line to the ListItem collection for ddlRequisitioner, I do not get the blank line. Can I not add items if I am using a BindingSource for the drop down list?

Here's my code:
            // Get data for drop down lists
            this.oUsers.GetAllActiveUsers();
            this.oUsers.GetApprovers();
            this.oInvclass.GetAllData();

            //// Add blank line to the requisitioner and inventory class drop down lists
            ////  and initialize the values to 0.
            this.ddlRequisitioner.Items.Add(new ListItem(string.Empty, "0"));
            this.ddlRequisitioner.SelectedValue = "0";
            this.ddlInvClass.Items.Add(new ListItem(string.Empty, "0"));
            this.ddlInvClass.SelectedValue = "0";

            // load values for approvers drop down
            IDataReader rApprovers = oUsers.ReadApprovers();
            while (rApprovers.Read())
            {
                this.ddlApprovers.Items.Add(new ListItem(rApprovers.GetString(1), rApprovers.GetString(0)));
            }
            rApprovers.Close();

            this.ddlApprovers.Items.Add(new ListItem(string.Empty, "0"));
            this.ddlApprovers.SelectedValue = "0";
Thanks.

Linda

[UPDATE]
The problem is that the data binding happens after the load method. When I moved the code to add the new list item to an overload of the OnPreRender method, it worked correctly.
Linda Harmes
HiBit Technologies, Inc.
Reply
Map
View

Click here to load this message in the networking platform