• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1146
  • Last Modified:

DropDownList in FormView - Show Selected Item in a Label

I have a dropdownlist (DropDownList1) in a formview (FormView1).

How do I show the selected item in a label (Label1) outside of the formview?

At the moment I have the following code but it only shows the initial dropdown value and does not update the label when the selected item changes. I realise I somehow have to incorporate the dropdown selected item change event into the code but I’ve no idea how & where.


protected override void OnInit (EventArgs e)
FormView1.ItemCreated += new EventHandler (FormView1_ItemCreated);
base.OnInit (e);

protected void FormView1_ItemCreated (Object sender,EventArgs e)
FormViewRow  row = FormView1.Row;
DropDownList ddl = (DropDownList)row.FindControl(“DropDownList”);
Label1.Text =ddl.SelectedItem.Text;
  • 2
1 Solution
try something like this
void FormView1_ItemCreated(object sender, EventArgs e)
           DropDownList  tmpDDL = (DropDownList)FormView1.Row.FindControl("DropDownList");
            if (tmpDDL != null)

I have tested the code but it should work

doolinnAuthor Commented:

sorry but adding an if statement to my code still does not invoke the change to the label text. any more thoughts..thanks
doolinnAuthor Commented:
just realised I should have had autopostback = true on the dropdown...whoops.!
PAQed with points refunded (500)

EE Admin
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now