SelectedValue vs SelectedItem.Value of DropDownList

后端 未结 5 1773
猫巷女王i
猫巷女王i 2020-12-08 09:37

I\'m working on an old project written and then patched by several people over the years. At some places they have used SelectedValue property and other places they used Sel

5条回答
  •  情书的邮戳
    2020-12-08 10:24

    Be careful using SelectedItem.Text... If there is no item selected, then SelectedItem will be null and SelectedItem.Text will generate a null-value exception.

    .NET should have provided a SelectedText property like the SelectedValue property that returns String.Empty when there is no selected item.

提交回复
热议问题