Greetings,
PROBLEM: I'm unable to 'automatically' have a DropDownList item 'selected' while adding multiple items directly to the ListItemCollection.
In the example below, I basically need to display the correct department in a DropDownList (as the SelectedItem while also listing all other departments) based on a corresponding text/value from another DropDownList.
Here is my code:
While dtr.Read()
drpd_ID.Items.Add( New ListItem( dtr( "d_Name" ), dtr( "d_ID" ) ) )
End While
I was thinking I could simply insert
in the blue section above, but it didn't work.
I greatly appreciate any help you can provide
PROBLEM: I'm unable to 'automatically' have a DropDownList item 'selected' while adding multiple items directly to the ListItemCollection.
In the example below, I basically need to display the correct department in a DropDownList (as the SelectedItem while also listing all other departments) based on a corresponding text/value from another DropDownList.
Here is my code:
Code:
<%@ Import Namespace="System.Data.OleDb %>
<script runat="server">
Sub Page_Load()
Dim cn As OleDbConnection
Dim strSQL As String
Dim cmd As OleDbCommand
Dim dtr As OleDbDataReader
cn = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=c:\data.mdb" )
strSQL = "SELECT d_ID, d_Name " & _
"FROM tblDepartment " & _
"ORDER BY d_Name"
cmd = New OleDbCommand( strSQL, cn )
cn.Open()
dtr = cmd.ExecuteReader()
While dtr.Read()
drpd_ID.Items.Add( New ListItem( dtr( "d_Name" ), dtr( "d_ID" ) ) )
End While
Code:
dtr.Close()
cn.Close()
End Sub
</script>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<form Runat="Server">
<asp:DropDownList id="drp_Name" Runat="Server">
<asp:ListItem Text="Curly" Value="1" />
<asp:ListItem Text="Larry" Selected="True" Value="2" />
<asp:ListItem Text="Moe" Value="3" />
</asp:DropDownList>
<br>
<asp:DropDownList id="drpd_ID" Runat="Server">
</asp:DropDownList>
</form>
</body>
</html>
I was thinking I could simply insert
Code:
Selected="True"
I greatly appreciate any help you can provide