Dropdown gets cleared

后端 未结 5 1054
南笙
南笙 2021-01-29 04:16

I have one asp.net application, in which i have one dropdown which is binded to dataset. But after selecting one item, the drop down gets cleared all the value, How we can resol

相关标签:
5条回答
  • 2021-01-29 04:28

    Set the AppendDataBoundItems property of the dropdown to true and this will allow you to have a mix of databound items and non databound items (otherwise that insert statement is clearing your list)

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.appenddatabounditems.aspx

    0 讨论(0)
  • 2021-01-29 04:32

    Do you have viewstate disabled on the page? Since you are only loading the items into the dropdownlist on the first load of the page, if viewstate is not enabled there will be nothing in the list after the postback.

    0 讨论(0)
  • 2021-01-29 04:39

    Not positive, but I've seen in other languages and false interpretation...

    You have your product Value as convert of ToDecimal which implies 99.999 for example.

    If your ID that you are binding to is based on a whole number (ie: Integer basis), the bound value won't match... even if Value = 1 vs Value = 1.00 it won't match and will not be considered a valid "value" that matches your list. Convert your answer to a whole/integer number and it might do what you expect.

    0 讨论(0)
  • 2021-01-29 04:43

    Without seeing the full source for the page I am simply speculating, but have you disabled ViewState on the page? If so, the DropDownList cannot retain its values between postbacks and the lists will have to be reloaded each time.

    0 讨论(0)
  • 2021-01-29 04:47

    From your question if I understand correctly you dont want the dropdown list to rebind if it is populated. Also please check your viewstate, this should not be happening, unless you have disabled viewstate

     protected void Page_Load(object sender, EventArgs e)
    {        
      if (!IsPostBack && ddlProduct.Items.count <=0 )
            BindProductDdl();
    

    }

    0 讨论(0)
提交回复
热议问题