473,409 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

pre-populate a dropdown list with ID values (int) from a datareader

Hi,

I am having difficulty with trying to pre-populate a dropdown list from a datareader. The list should bind with the ID from a table to display its text value. For example to display the region "Oregon" the ID=5, "Florida" the ID=12 etc...

this is the code I am using that fails:

ddlRegion.DataValueField = rdr.GetOrdinal("regionID").ToString();
ddlRegion.DataBind();


DataBinding: 'System.Data.DataRowView' does not contain a property with the name '1'

Your feedback will be greatly appreciated !...
Thank you.
Dec 23 '11 #1
4 2749
adriancs
122 100+
A drop down list, do you mean ComboBox?

If yes, you can bind it into DataTable.

Expand|Select|Wrap|Line Numbers
  1. DataTable dt = new DataTable();
  2. dt.Columns.Add("Display", typeof(string));
  3. dt.Columns.Add("Value", typeof(int));
  4. dt.Rows.Add("Oregon", 5);
  5. dt.Rows.Add("Florida", 12);
  6. comboBox1.DataSource = dt;
  7. comboBox1.DisplayMember = dt.Columns["Display"] + "";
  8. comboBox1.ValueMember = dt.Columns["Value"] + "";
  9.  
  10. // To select
  11. comboBox1.SelectedValue = 5;
  12. MessageBox.Show(comboBox1.Text);
  13.  
  14. comboBox1.SelectedIndex = 1;
  15. MessageBox.Show(comboBox1.Text);
  16.  
  17. // Getting the selected value
  18. MessageBox.Show(comboBox1.SelectedValue + "");
Personally, I prefer to use a dictionary than binding it into a DataTable.
Dec 23 '11 #2
Hi there,

Thank you for your time and reply. I apologise as I may not have explained my problem correctly so I'll describe the purpose of the code.

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 bibding 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 originally saved.

That's where my problem lies....

Thank you for your help and advice with this, and best wishes to you and your loved one over the festive season.

Boris.
Dec 23 '11 #3
adriancs
122 100+
I see. You may consider to post this question at the ASP section:
http://bytes.com/topic/asp-classic/
Dec 24 '11 #4
Thank you for your feedback. I will definitely re-post this into the ASP.NET forum as suggested. Once again thank you for your time and take care.

Boris.
Dec 25 '11 #5

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

Similar topics

2
by: GriffithsJ | last post by:
Hi I have been given some text that needs to be displayed on a web page. The text is pre-formatted (includes things like lists etc) and displays okay if I wrap it using the <pre/> tag. ...
3
Pre
by: Neal | last post by:
A few questions about pre... When presenting preformatted text using the white-space: pre; property/value, Opera renders long lines at small viewport widths as exiting the borders of the...
7
by: Alan Illeman | last post by:
How do I set several different properties for PRE in a CSS stylesheet, rather than resorting to this: <BODY> <PRE STYLE="font-family:monospace; font-size:0.95em; width:40%; border:red 2px...
7
by: Roderik | last post by:
Hi, When I use <pre> inside my <td> cells, the text won't flow to a new line and the table gets to large in width. This will appear in Firefox this way, Internet Explorer will wrap the lines,...
2
by: Buck Turgidson | last post by:
I want to have a css with 2 PRE styles, one bold with large font, and another non-bold and smaller font. I am new to CSS (and not exactly an expert in HTML, for that matter). Is there a way to...
3
by: Michael Shell | last post by:
Greetings, Consider the XHTML document attached at the end of this post. When viewed under Firefox 1.0.5 on Linux, highlighting and pasting (into a text editor) the <pre> tag listing will...
5
by: Porthos | last post by:
I'm authoring an XML document and using the <pre> html tag for the portions that are not dynamically generated. The <pre> text is displaying in a smaller font size (and I believe different font)...
1
by: R0bert Nev1lle | last post by:
Here's my next IE challenge (or frustration). It deals with the overflow attribute. Overflow property was a challenge on my page since the page emulates position fixed for IE. The present...
8
by: Jarno Suni not | last post by:
It seems to be invalid in HTML 4.01, but valid in XHTML 1.0. Why is there the difference? Can that pose a problem when such a XHTML document is served as text/html?
7
by: Rocky Moore | last post by:
I have a web site called HintsAndTips.com. On this site people post tips using a very simply webform with a multi line TextBox for inputing the tip text. This text is encode to HTML so that no...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.