-1

Dropdownlist从数据库中读取其值并显示它们。我希望页面加载时dropdownlist什么都不显示(即selectedindex= -1)和用户选择值。任何的想法?

4

2 回答 2

3

添加一个空的未绑定项

<asp:DropDownList runat="server" AppendDataBoundItems="true">
    <asp:ListItem Selected="true" Text="" Value="" />
</asp:DropDownList>
于 2012-08-09T16:19:46.273 回答
0

您可以从后端或直接从下拉列表中添加一个空数据列表项:

从数据库方面:

SELECT
  1 as SortOrder,
  DataValueField,
  DataTextField
FROM
  YourTable
UNION ALL
SELECT
  0 As SortOrder,       --this ensures the empty item is at the top of the list
  0 As DataValueField,
  '' As DataTextField --or 'Select One'
Order By
  SortOrder,
  Value

或者直接作为列表项

<asp:ListItem Selected="True" Text="Select One" Value="0" AppendDataBoundItems="true" />

于 2012-08-09T16:21:45.803 回答