Solved

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

Posted on 2004-09-02
3
190 Views
Last Modified: 2010-04-07
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
Comment
Question by:bullrout
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
shovavnik earned 500 total points
Comment Utility
Try either:

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

Or (even better):

lstRegion.SelectedValue = dr("state")
0
 
LVL 8

Expert Comment

by:shovavnik
Comment Utility
You may need to use .ToString():

dr("state").ToString()

but I'm not sure.
0
 
LVL 5

Author Comment

by:bullrout
Comment Utility
Hi there,

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

Sean
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now