I have a asp:dropdownlist
that is being populated by a sqldatasource
.
我有一个asp:dropdownlist,由sqldatasource填充。
<asp:DropDownList ID="ddlDepartment" runat="server" DataSourceID="sdsPharmacy"
DataTextField="departmentName" DataValueField="departmentName"
OnSelectedIndexChanged="ddlDepartment_SelectedIndexChanged" AutoPostBack="True">
</asp:DropDownList>
How do I set the first Selection to something like "Select One" without dropping the table and recreating it and adding that as the first value?
如何将第一个选择设置为“选择一个”而不删除表并重新创建它并将其添加为第一个值?
3 个解决方案
#1
2
Set AppendDataBoundItems="true"
in your DropDownList after AutoPostBack="True"
and add a static item inside the DropDownList tag <asp:ListItem Text="Select One" Value="" Selected="True" />
在AutoPostBack =“True”之后在DropDownList中设置AppendDataBoundItems =“true”并在DropDownList标记内添加一个静态项
#2
0
<asp:DropDownList ID="ddlDepartment" runat="server" DataSourceID="sdsPharmacy"
DataTextField="departmentName" DataValueField="departmentName"
OnSelectedIndexChanged="ddlDepartment_SelectedIndexChanged" AutoPostBack="True"
SelectedValue=<%#Bind("departmentName")%>
</asp:DropDownList>
In the departureName you will give the value of departmentName you want to be selected. I suppose that the value you want to be selected is in the dataset of your datasource. Otherwise the correct answer is the answer of Andrew.
在departureName中,您将给出要选择的departmentName的值。我想您要选择的值是在数据源的数据集中。否则正确答案就是安德鲁的答案。
#3
0
Why would you have to drop and re-create the table to add a row? Are you depending on the "natural" order of the table, populating your drop down with a SELECT with no ORDER BY? A table is an unordered set of rows by definition, so if you're currently relying on this natural order, this can change with a plan change, service pack, index change, statistics change, data change, etc. etc. Stop relying on it and add an actual sort column if you want a predictable, deterministic sort in your output.
为什么要删除并重新创建表以添加行?您是否依赖于表的“自然”顺序,使用没有ORDER BY的SELECT填充下拉列表?根据定义,表是一组无序行,因此,如果您当前依赖于此自然顺序,则可以通过计划更改,Service Pack,索引更改,统计信息更改,数据更改等进行更改。停止依赖如果您希望在输出中进行可预测的确定性排序,请添加实际排序列。
#1
2
Set AppendDataBoundItems="true"
in your DropDownList after AutoPostBack="True"
and add a static item inside the DropDownList tag <asp:ListItem Text="Select One" Value="" Selected="True" />
在AutoPostBack =“True”之后在DropDownList中设置AppendDataBoundItems =“true”并在DropDownList标记内添加一个静态项
#2
0
<asp:DropDownList ID="ddlDepartment" runat="server" DataSourceID="sdsPharmacy"
DataTextField="departmentName" DataValueField="departmentName"
OnSelectedIndexChanged="ddlDepartment_SelectedIndexChanged" AutoPostBack="True"
SelectedValue=<%#Bind("departmentName")%>
</asp:DropDownList>
In the departureName you will give the value of departmentName you want to be selected. I suppose that the value you want to be selected is in the dataset of your datasource. Otherwise the correct answer is the answer of Andrew.
在departureName中,您将给出要选择的departmentName的值。我想您要选择的值是在数据源的数据集中。否则正确答案就是安德鲁的答案。
#3
0
Why would you have to drop and re-create the table to add a row? Are you depending on the "natural" order of the table, populating your drop down with a SELECT with no ORDER BY? A table is an unordered set of rows by definition, so if you're currently relying on this natural order, this can change with a plan change, service pack, index change, statistics change, data change, etc. etc. Stop relying on it and add an actual sort column if you want a predictable, deterministic sort in your output.
为什么要删除并重新创建表以添加行?您是否依赖于表的“自然”顺序,使用没有ORDER BY的SELECT填充下拉列表?根据定义,表是一组无序行,因此,如果您当前依赖于此自然顺序,则可以通过计划更改,Service Pack,索引更改,统计信息更改,数据更改等进行更改。停止依赖如果您希望在输出中进行可预测的确定性排序,请添加实际排序列。