Asp.NET DropDownList SelectedItem.Value not changing

前端 未结 5 1795
庸人自扰
庸人自扰 2021-01-07 23:40

markup:

            
相关标签:
5条回答
  • 2021-01-08 00:10

    hey for first index to add all not required to add. you need to insert on particular index number

    MyList.Items.Insert(0, "ALL");
    
    0 讨论(0)
  • 2021-01-08 00:18

    Yes you are missing to add drop down list Autopostback=true..

    Please try with following in your .aspx page

    0 讨论(0)
  • 2021-01-08 00:22

    Your code is probably executing after postback too, clearing the box, hence losing selection and all.

    If so, try wrapping the code in something like if( !Page.IsPostBack ) { ... }.

    0 讨论(0)
  • 2021-01-08 00:23

    If you're databinding in Page_Load, you're essentially also resetting the SelectedItem.

    You should wrap whatever binding code that exists in Page_Load inside an if(!IsPostBack) block.

    if(!Page.IsPostBack)
    {
    
        // Your binding code here ...
    
    }
    
    0 讨论(0)
  • 2021-01-08 00:24

    So this answer is the "obvious" solution to the most common cause. However, there is one more surprising issue that can cause this! My list values came from a database and the values had linefeed and carriage return: "\r\n". These values look like an innocent space, but actually they are not! My solution was to remove these hidden Char values. Hope it helps.

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