Solved

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

Posted on 2004-09-02
3
195 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
shovavnik earned 500 total points
ID: 11962032
Try either:

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

Or (even better):

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

Expert Comment

by:shovavnik
ID: 11962034
You may need to use .ToString():

dr("state").ToString()

but I'm not sure.
0
 
LVL 5

Author Comment

by:bullrout
ID: 11968981
Hi there,

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

Sean
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 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