DropDownList item selected from QueryString
Posted on 2007-07-26
I am populating a dropdown list from a database with the following code
I am passing a suspectid to the page via a query string. I would like to have the dropdown list item that matches the querystringvalue to be automatically selected when the page is loaded. This was easy enough to do in classic ASP. I am wondering how I can do this with .NET. Any suggestions?
I want the entire list to show from the db but I do want the specific item selected.
Page Load subroutine --
objCommand = New ODBCCommand("SELECT suspectid, lastname FROM suspects ", objConnection)
objReader = objCommand.ExecuteReader()
suspectid.DataSource = objReader
suspectid.DataValueField = "suspectid"
suspectid.DataTextField = "lastname"
Form Tag/Control ---
<asp:DropDownList id="suspectid" runat="server" />