Hi,
You need to find the item that has the text value "value 2" and then get its
index value. Once you have the index value, you can set the SelectedIndex to
that value.
Here's a quick way to accomplish all three:
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles MyBase.Load
If Not IsPostBack Then
ddl.SelectedInd ex = ddl.Items.Index Of _
(ddl.Items.Find ByText("value 2"))
End If
End Sub
<asp:DropDownLi st id="ddl" runat="server">
<asp:ListItem Value="0">value 1</asp:ListItem>
<asp:ListItem Value="1">value 2</asp:ListItem>
<asp:ListItem Value="0">value 3</asp:ListItem>
<asp:ListItem Value="1">value 4</asp:ListItem>
</asp:DropDownLis t>
Does this help?
Ken
Microsoft MVP [ASP.NET]
"huzz" <hu**@discussio ns.microsoft.co m> wrote in message
news:C6******** *************** ***********@mic rosoft.com...
How do i make a dropdownlist selected value based on the value i retrive
from
the database.
Basically i have an edit page and like to display the default value in a
dropdown list from the database.
for example: if the ddl_value is 2 from the database i want the second
list
item to be selected by default.
<asp:DropDownLi st id="ddl" runat="server">
<asp:ListItem Value="0">value 1</asp:ListItem>
<asp:ListItem Value="1">value 2</asp:ListItem> // make this dynamically
selected
<asp:ListItem Value="0">value 3</asp:ListItem>
<asp:ListItem Value="1">value 4</asp:ListItem>
</asp:DropDownLis t>
I am using the dropdownlist inside a repeater.. and only retriving single
record at a time based on a querystring... and using a datareader to fill
the
form.
Many thanks in advance..