By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,162 Members | 1,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,162 IT Pros & Developers. It's quick & easy.

Pre-populate a dropdownlist before showing form for editing

P: 5
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
Share this Question
Share on Google+
2 Replies


P: 1
Hello, try something like this

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

hope it helps !
Jan 22 '12 #2

P: 5
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.