[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Pass selected text field from drop down list? c#

Posted on 2009-05-04
5
Medium Priority
?
589 Views
Last Modified: 2012-05-06
Is there any way to pass in the selected text field from a drop down list?

I need to pass it in as a string value to this method:

Controller.AddImage(userID, ddlAlbum.SelectedTextField, txtImageName.Text);
protected void Page_Load(object sender, EventArgs e) {
            Albums = new DataSet();
            Albums = NAITBook.Controller.GetAllAlbums(userID);
            ddlAlbum.DataSource = Albums.Tables[0];
            ddlAlbum.DataTextField = "Name";
            ddlAlbum.DataValueField = "AlbumID";
            ddlAlbum.DataBind();
}

Open in new window

0
Comment
Question by:tqrecords
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 9

Expert Comment

by:tculler
ID: 24300039
This all depends on the type of objects stored in the drop-down list (I'm assuming you mean a System.Windows.Forms.ComboBox?). Any time you pass an object to a method like this, such as adding it to a ComboBox, it will call the ToString method on each item top obtain how it should be displayed. Some objects have a "friendlier" ToString method than others, so I'll need to know what type of objects are stored within the ComboBox/ListBox, as well as what format you need the String in.

Or, you can just use the SelectedValue property, like so:

Object selectedValue = nameOfComboBox.SelectedValue;
0
 

Author Comment

by:tqrecords
ID: 24300123
hey,

thanks for the reply but I figured it out

just changed the ddlAlbum.DataValueField to "Name"
0
 
LVL 7

Accepted Solution

by:
ajolly earned 2000 total points
ID: 24300692
I will not suggest you to change the DataValueField to "Name"
This is not suggested.

Usually, we keep the DataValue field to be bound with the internal value or id field.
and the DataTextField to the one field which we want to display.

If any moment, you want to get the value/text of the selected item, use following:

for value = ddlAlbum.SelectedValue          or ddlAlbum.SelectedItem.Value
for text = ddlAlbum.SelectedItem.Text

0
 

Author Comment

by:tqrecords
ID: 24300731
OMG you know how long I was looking for that!!??

I knew it was so simple yet I could not find it anywhere!

Thanks alot ajolly!
0
 

Author Closing Comment

by:tqrecords
ID: 31577803
Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

656 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