Does anyone know how can I default selected value in asp:DropDownList?
Following is my code:
<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>
How can I able to selected the display list which is the TestID is 1?
You have couple of options first one is below if you want to do this by default.
<asp:ListItem Selected="True"></asp:ListItem>
Or you can do this in code
Test.selectedIndex = 0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With