Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

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>
0
bullrout
Asked:
bullrout
  • 2
1 Solution
 
shovavnikCommented:
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now