Binding the default value of a static listmenu control to a db field at runtime?

Hi There,

I am trying to default my listmenu to the stored value in the DB, the list itself is static but the values stored in the db are the same even in case.

I have tried 3 methods (below), has anyone got any better ideas?

Sean - thanks in advance for your answer

                                'lstRegion.Items.FindByText(dr("state"))
             ' lstRegion.Items.FindByValue(dr("state"))
             lstRegion.SelectedItem.Value = dr("state")


<ASP:DropDownList id=lstRegion name=lstRegion maxlength= "40" CssClass="dropstyle" runat=server>
            <asp:ListItem>Please Select</asp:ListItem>
            <asp:ListItem Value="New South Wales">New South Wales</asp:ListItem>
            <asp:ListItem Value="Victoria">Victoria</asp:ListItem>
            <asp:ListItem Value="Tasmania">Tasmania</asp:ListItem>
            <asp:ListItem Value="South Australia">South Australia</asp:ListItem>
            <asp:ListItem Value="Western Australia">Western Australia</asp:ListItem>
            <asp:ListItem Value="Northern Territory">Northern Territory</asp:ListItem>
            <asp:ListItem Value="Queensland">Queensland</asp:ListItem>
            </ASP:DropDownList>
LVL 5
bullroutAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
shovavnikConnect With a Mentor Commented:
Try either:

lstRegion.Items.FindByValue(dr("state")).Selected = true

Or (even better):

lstRegion.SelectedValue = dr("state")
0
 
shovavnikCommented:
You may need to use .ToString():

dr("state").ToString()

but I'm not sure.
0
 
bullroutAuthor Commented:
Hi there,

this syntax seemed to work fine "lstRegion.SelectedValue = dr("state")" thanks for the help.

Sean
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.