Solved

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

Posted on 2013-10-28
1
365 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
[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
1 Comment
 
LVL 8

Accepted Solution

by:
johny_bravo1 earned 500 total points
ID: 39608628
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…

710 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