Solved

How to select dropdown  item and how to display field in dropdown

Posted on 2013-10-28
1
354 Views
Last Modified: 2013-11-04
Hi,

Scenario 1:
for example I have one dropdown.Dropdown contains 4 items.I want to select 1 item in the dropdown.
Question:How to select dropdown item in C#?(is it dropdown1.selected value or selected item.text?)

Scenario 2:

I want to display some text(coming from database) in to dropdown.for example

( string test="Test1"

dropdown1.Text=test;  Is it correct?)

Can u plese help me regading above two scenarios?
0
Comment
Question by:mannevenu26
1 Comment
 
LVL 8

Accepted Solution

by:
johny_bravo1 earned 500 total points
Comment Utility
How you bind your dropdowns?

dropdown1.DataSource = ds; (ds is DataSet object);
dropdown1.DataTextField = "ItemName"; (Text you want to display)
dropdown1.DataValueField = "ItemId"; (Id )
dropdown1.DataBind();

Now if you do,
dropdown1.SelectedItem.Text you will get the selected text from user.
dropdown1.SelectedItem.Value will give you the Id of the selected text.

Secenario 2:
dropdown1.Items.Add("Your string");
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now