Solved

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

Posted on 2004-09-02
3
193 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
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 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