I have a drop down list that looks like this:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem Text="Text1" Value="6,08/04/2015,P"></asp:ListItem>
<asp:ListItem Text="Text2" Value="5,11/17/2014,S"></asp:ListItem>
<asp:ListItem Text="Text3" Value="4,05/26/2014,P"></asp:ListItem>
<asp:ListItem Text="Text4" Value="3,01/20/2014,A"></asp:ListItem>
<asp:ListItem Text="Text5" Value="2,10/31/2013,G"></asp:ListItem>
<asp:ListItem Text="Text6" Value="1,04/09/2013,P"></asp:ListItem>
</asp:DropDownList>
I need to be able to get a date from a database and try to automatically select the correct date from the drop down list.
my code behind is as follows:
dim strDate as string = "10/31/2013"
DropDownList1.selectedvalue.contains(strDate)
something like that but it does not select the correct value from the drop down.
Either of these should work. I would loop through the dropdown items collection and then split the value into an array. Validate that the values actually contain 3 values and get the second one to compare against strDate. Once you validate the value matches set the item as selected by either of the below methods and exit the For Each loop incase there are duplicates it would grab the 1st one.