Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
635
WebDropDown losing content after DataBind
posted

This looks like another bug in the WebDropDown.

When a WebDropDown is bound to a data source containing several items and the second item in the list is selected and then subsequently this dropdown is bound to a different data source containing only one item, the dropdown seems to be disabled and does not show any value.

This does not happen if any item other than the second in the dropdown is selected before the list is rebound. It also does not happen if the list is rebound to a data source with more that one item.

I have included some code to reproduce the problem: click the 'Set Three' button, select the second item and then click the  'Set One' button.

    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <ig:WebDropDown ID="WebDropDown2" runat="server" Width="224px" DisplayMode="DropDownList" TextField="second" ValueField="first" AutoPostBackFlags-SelectionChanged="On"><ClientEvents /></ig:WebDropDown><br />
        <asp:Button ID="Button1" runat="server" Text="Set One" onclick="Button1_Click" />
        <asp:Button ID="Button2" runat="server" Text="Set Three" onclick="Button2_Click"  />
    </div>
    </form>
    <script runat="server">
        public class myObject
        {
            public myObject(string first, string second)
            {
                this.first = first;
                this.second = second;
            }
            public string first { get; set; }
            public string second { get; set; }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            List<myObject> lTwo = new List<myObject>();

            lTwo.Add(new myObject("1", "Not Set"));
            WebDropDown2.DataSource = lTwo;
            WebDropDown2.DataBind();
            WebDropDown2.SelectedValue = WebDropDown2.Items[0].Value;
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            List<myObject> lTwo = new List<myObject>();
            lTwo.Add(new myObject("1", "One"));
            lTwo.Add(new myObject("2", "Two"));
            lTwo.Add(new myObject("3", "Three"));
            WebDropDown2.DataSource = lTwo;
            WebDropDown2.DataBind();
            WebDropDown2.SelectedValue = WebDropDown2.Items[0].Value;
        }
    </script>

 

Parents Reply Children