Determine the database field names populating a dropdownlist

Hello all!
I'd like to know if it's possible to determine the field names that are involved with the data that is presented in a dropdownlist.

 I have the following snippet of code:

DropDownList ddl = (DropDownList)row.FindControl("DDL_ContactMethod");
string selectedContactMethod = ddl.SelectedValue;

I can see the values that are selected, but I can't determine how to get the field names.  I'm guessing I'll have to access the datasource in some manner?

Thanks all!

0
mcarthey
11/21/2008 8:59:40 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

5 Replies
330 Views

Similar Articles

[PageSpeed] 26


ddl.SelectedItem.Text

 


There are no stupid questions, only easy answers. However, the quality of assistance you receive (if any) is directly proportional to the quality of your request.

p.s. Please remember to "mark as answer" all posts that answer your question.
0
CharlesF
11/21/2008 9:47:13 PM

In case I assumed wrong thinking you wanted to get the text of the item instead of the value, and you actually wish to access the field in the DataSource, then do so via either the .DataTextField or .DataValueField properties of the DropDownList.


There are no stupid questions, only easy answers. However, the quality of assistance you receive (if any) is directly proportional to the quality of your request.

p.s. Please remember to "mark as answer" all posts that answer your question.
0
CharlesF
11/21/2008 10:02:55 PM

Come to think of it, if you wish to access the actual data, instead of the names of the fields, then you might do so via the .GetData method. This method returns a DataSourceView object which allows you to access the data directly.


There are no stupid questions, only easy answers. However, the quality of assistance you receive (if any) is directly proportional to the quality of your request.

p.s. Please remember to "mark as answer" all posts that answer your question.
0
CharlesF
11/21/2008 10:18:16 PM

Thanks for the ideas.  I'd actually like to access the name of the database column.  For example, the following query:

 select * from account where accountnumber = 10;

NAME, PHONE, STATE
Bill, 555-1212, NY
Tom, 555-1111, OH

I'd like to see the values NAME, PHONE and STATE instead of the actual returned data.

Thanks!

0
mcarthey
11/24/2008 3:52:47 PM

You haven't specified how you are populating your DropDownList, so I'm unable to give you a very specific example.

But in general this is how  you'd do it...

(where the ds is the DataSet) 

 

foreach(DataColumn column in ds.Tables[0].Columns) 
{ 
    Trace.WriteLine(column.ColumnName); 
} 
 

There are no stupid questions, only easy answers. However, the quality of assistance you receive (if any) is directly proportional to the quality of your request.

p.s. Please remember to "mark as answer" all posts that answer your question.
0
CharlesF
11/24/2008 6:00:27 PM
Reply:

Similar Artilces:

how to get a control ID from a bind field name / bound field (column) name from a formview's control
I have a form view which is bound to a table, now from codebehind file I need to apply some formatting based on some of the field's bound control. For example, if Formview1 is bound to Employee table, and it's item template has a control with ID "Label1" which is bound to "EmployeeJoinDate" . Now, I have a different table which has a list of field name(EmployeeJoinDate is one of them), all of which should be applied some formatting based on some condition. Now I can take two approach for that, but I am stuck at both:  1. If I can somehow get the contro...

Populate DropdownList from database inside other controls!
 Hello all, I have a dropdownlist inside the TabContainer control. I try to populate data from a table to dropdown list using its ID, but display the error due to not recognized the dropdownlist ID in code behind. Any suggestions how to fix above error is appreciated. Thanks in advance. Usually it should work..but donno y its not working 4 u, but workaround 4 u r problem is find dropdown in tabcontainer using FindControl method DropDownList ddl = Tabcontainername.FindControl("your drop down List name ") as DropDownList; then ddl is your dropdown in tabcontainer uase...

How do you populate a dropdownlist with the contents of a field of a database?
If it is possible to populate a dropdownlist with the contents of a field of a database?  (and maybe have it ignore duplicates--each entry in the dropdown being unique).  If this is possible, could someone talk me through it? -LarryLarry Dechent - Sampson Coatingswww.wemakebetterpaint.com has 29 examples (C# & VB) to help beginners with ASP.NET. You can filter your column with a DISTINCT  in your select statement For example: SELECT DISTINCT Agentid, agentName FROM agents If you use a datasource declaratively: <asp:SqlDataSource ID="SqlDS1" runat="server" Select...

populating a ddl with field names from a database
Hi all,I like to be able to populate a drop down list with field names from a database table. I can get the values in the fields no problem, but am unable to get the actual field names. To get the values I use a simple SQL line 'Select * from tbTest1', but does anyone know how to the get the names of each of each of the fields??Thanks in advance. SELECT * will return all the fields in the table. IF you only need some fields you need to list out the columns you want in the SELECT statement. sample:SELECT   column1,   column2FROM   table**********...

Populating multiple dropdownlists from a single database field.
Hi,For this project I'm using .Net 1.1 and VB. I'm trying to create ddl's for the 'date of birth'. That is, one ddl for month, one for day, and one for year. I want to combine those values and update a single 'dob' field of the table (currently in MS Access). Also, I need to be able to retrieve an existing dob and have each ddl show the appropriate value. For example, if I login to the site and select 'January', '10', '1970' from the individual ddls and click submit, the date should be stored as '01/10/1970' in the 'dob' fie...

Populate a DropDownList from a SQL Server Database in c#.net
i have this working in vb but i need it in c#...only because i have all the rest of the pages already in c#...otherwise id use vb heres a sample but i get an error  "C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %> "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> "server"> public void Page_Load(object Source, EventArgs E) { if (!Page.IsPostBack) { SQLConnection oConn; ...

How can bind a database field to DropDownList control in ListView?
It's easy to bind a field to ImageButton control, I can pass ChartProjectID field to CommandArgument propertybut there is not CommandArgument property in DropDownList control, how can I do? Thanks!     protected void ImageButtonChart_Click(object sender, ImageClickEventArgs e)   {       ImageButton myImageButton= (sender as ImageButton);       string ID=myImageButton.CommandArgument    }                   <as...

How to change the name of the name-field in a dropdownlist?
Hi, I have a dropdownlist like this:<asp:DropDownList ... DataValueField="Id" DataTextField="Name" runat="server" /> Now I want to change the name of the DataTextField values. For example: this dropdownlist shows a list with names like James, Mike, etc. Now I want to change these names for example to 'mr. James', 'mr. Mike' etc. How can I do that? Thanks!Please remember to 'Mark as Answer' if this post answered your question! In your SELECT query, you can change the name  field like this: "SELECT id, 'Mr. ' + Name as Name FROM yourtable" You don't ne...

Insert data from a dropdownlist and textbox control into a database ( vb.net)
Hi everyone, I am creating an application for my students.  I teach piano.  There are three levels for them: Beginner, Intermediate, Advanced. After they have logged in, they are given the opportunity to select various pieces of sheet music to learn according to their level from a dropdown list control.  I have created the database which lists the sheet music and bound it to the dropdownlist control.  I have also added a textbox control where I want them to type in the reason why they selected the particular piece of music to learn (I know, kids hate writing essays, but ...

Dynamic Template
Greetings - I am creating Grid Templates using ITemplate, and am trying to obtain the the form field name generated by .Net. From looking at the html, .Net is generating a name for a textbox similar to the following: name="dgDataGrid:_ctl4:txt_TextBox" Is it possible to retieve this from the InstantiateIn sub within my template class? The only thing I have access to is a reference to the container control. I can get the ID of the control "txt_TextBox" because I am assigning it there, however I am not sure how to get the "dgDataGrid:_ctl4:" piece. ...

Populate Label, Dropdownlist, Textbox and Gridview from a SQL DataBase using VB.NET
 Good Day, Please help me, i need a VB.NET code for my web appz, i already know how to connect to a sql server database using this codes Dim conn As New Data.OleDb.OleDbConnection conn = New Data.OleDb.OleDbConnection("Provider=SQLOLEDB.1;Password=******;Persist Security Info=True;User ID=***;Initial Catalog=Database;Data Source=ServerName") conn.Open() Dim cmd As Data.OleDb.OleDbCommand cmd = New Data.OleDb.OleDbCommand("Select Field1 From Table1", conn)So i would like to ask how can i bind this VB.NET connection code to a Label and/or Dropdownlist and...

Populating a label control with a field from SQLDataSource Field
I have a table with various fields. Some will be user entered and others will be populated from a database. I have a SQLDataSource object in my form. The data source only grabs one row of data from the table. I'm wondering how to use that data source to populate label objects. In other words: Dim Origin As Label = CType(DetailsView1.FindControl("lblPOL"), Label) Origin.Text = ??? Where ??? is the data I want to grab from my Data Source.  you dont have to assign any values from code behind as long you bind the datasource to your DetailsView and use a Boundc...

Can ADO.Net query/update a MS Access database that contains table and fields that contain blank spaces and characters such as "#" in their names?????
I've recently been assigned an asp.net/MS Access project. My code works fine; however, there are table and fields in the Access database that contain blank spaces and characters such as "#" in their names. For example there is a table named "Purchase Orders" and in this table there are a few column fields with names such as "PO#" and “Customer PO#". My question: Is there some sort of wrapping method that I need to implement to allow my ADO.net objects (particularly the "OleDbDataAdapter" and the "DataRow") to accept these naming...

How to dynamically populate a dropdownlist control in a InsertItemTemplate of DetailView control.
Guys,I have a very basic problem. I have two dropdownlist in InsertItemTemplate of a Detailview Control for Category and Subcategory. I am getting list of catetories and subcategories in respective dropdown list. Now i want to populate Subcategory dropdownlist based on the Value selected in the Category Dropdownlist. How can i pass CategoryID as parameter value for subcategory dropdownlist control at runtime? I can't see the Category dropdownlist contol name in the Databinding and popup comes to choose parameter. Any suggestions? Thanks in advance.   Positive attit...

Web resources about - Determine the database field names populating a dropdownlist - asp.net.presentation-controls

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 12/30/2015 10:24:25 AM