Hi Hazel,
Use DropDownList Item FindByText or FindByValue method.
Check this example. Now please take its reference and correct your code.
HTML
<asp:Label ID="lblCountry" Text="Malaysia" runat="server" />
<br />
<asp:DropDownList runat="server" ID="ddlCountries">
<asp:ListItem Text="Select" Value="0" />
<asp:ListItem Text="USA" Value="USA" />
<asp:ListItem Text="India" Value="India" />
<asp:ListItem Text="Malaysia" Value="Malaysia" />
</asp:DropDownList>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Set using FindByText.
if (ddlCountries.Items.FindByText(lblCountry.Text) != null)
{
ddlCountries.Items.FindByText(lblCountry.Text).Selected = true;
}
// Or
// Set using FindByValue.
if (ddlCountries.Items.FindByValue(lblCountry.Text) != null)
{
ddlCountries.Items.FindByValue(lblCountry.Text).Selected = true;
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
' Set using FindByText.
If ddlCountries.Items.FindByText(lblCountry.Text) IsNot Nothing Then
ddlCountries.Items.FindByText(lblCountry.Text).Selected = True
End If
' Or
' Set using FindByValue.
If ddlCountries.Items.FindByValue(lblCountry.Text) IsNot Nothing Then
ddlCountries.Items.FindByValue(lblCountry.Text).Selected = True
End If
End If
End Sub