468,544 Members | 1,776 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,544 developers. It's quick & easy.

Pre-populate a dropdownlist before showing form for editing

Hi All,

I have a bit of a problem with which I have been "spinning my wheels" for a while, and any help or suggestion will be greatly appreciated.


I have an ASP.NET [New Member] form, where I capture club members and on that form there are ASP.NET dropdown lists for Gender and Region.

The table that fills the [Region] has 2 columns : ID, region... The member record saves the regionID as an Integer.

Another page lists in a gridview the individuals [memberID],[names], [Gender], [Region] (which is binding to the region table by ID) ... The gridview has links on the side to [Edit Member] or [Delete Member]...

When the [Edit Member] link is clicked, I get the [memberID] from the GridView row and I need to retrieve all its data from the [Member] table to pre-populate the form for editing.

As long as the data from the Datareader is (string) directly from the [member] table it is working fine, but I need to get the [regionID] to then retrieve the "text" value of the region to display in the [Region] dropdown list as the selected value that was originally saved for this member.

That's where my problem lies, I can't figure out how to set the DrpDwnList.DataValue with the ID saved in the member record, and get it to display the "text" associated to that ID from the [Region] table.....

Thank you for your time and help with this, and the very best to you over this festive season.

Boris.
Dec 25 '11 #1
2 1958
Hello, try something like this

YourComboBox.DataValueField = "IDField";
YourComboBox.DataTextField = "ValueField";
YourComboBox.DataSource = YourDataSource;
YourComboBox.DataBind();

hope it helps !
Jan 22 '12 #2
Hello,

I did manage to get it to work, and my solution is very similar to what you suggest.

Thank you very much for your reply, it is greatly appreciated.
Jan 24 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by GriffithsJ | last post: by
2 posts views Thread by Porthos | last post: by
21 posts views Thread by Headless | last post: by
Pre
3 posts views Thread by Neal | last post: by
7 posts views Thread by Alan Illeman | last post: by
2 posts views Thread by Buck Turgidson | last post: by
3 posts views Thread by Michael Shell | last post: by
14 posts views Thread by Schraalhans Keukenmeester | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.