有谁知道如何在 asp:DropDownList 中默认选择值?
以下是我的代码:
<tr>
<th align="right"><strong>Test: </strong></th>
<td>
<asp:DropDownList ID="Test" runat="server" DataSourceID="dsTest"
DataValueField="TestID" DataTextField="TestName" AppendDataBoundItems="true">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="dsTest" runat="server" ConnectionString="<%$ ConnectionStrings:Test %>"
SelectCommand="test_select" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>
</td>
</tr>
如何选择TestID为1的显示列表?
最佳答案
如果您想默认执行此操作,您有几个选项,第一个选项如下。
<asp:ListItem Selected="True"></asp:ListItem>
或者你可以在代码中做到这一点
Test.selectedIndex = 0;
关于c# - 如何在 asp :DropDownList 中默认选择值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5891023/