設置DropdownList的默認值,如果用新增空條目的辦法,新增的條目是在最後一條,即使默認選中也是排在最後面,用戶還要手動拉滾動條才能看到前面的條目,不合常理。
實際有一個很簡單的辦法:
在dropdownlist中加入一個AppendDataBoundItems="True"的屬性,然後設置一條靜態條目,內容爲空,當然也可以設置成“請選擇數據”之類的值。
具體如下
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" >
<asp:ListItem Value="0">Please Select</asp:ListItem>
</asp:DropDownList>
這樣綁定的數據只會追加到這條靜態數據之後,而默認選中的是這條靜態數據。