Solved

DropDownList in FormView - Show Selected Item in a Label

Posted on 2006-11-01
5
1,111 Views
Last Modified: 2012-06-21
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.

Thanks!


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;
}
0
Comment
Question by:doolinn
[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
  • 2
5 Comments
 
LVL 27

Expert Comment

by:Sammy
ID: 17848276
try something like this
void FormView1_ItemCreated(object sender, EventArgs e)
    {
       
           DropDownList  tmpDDL = (DropDownList)FormView1.Row.FindControl("DropDownList");
            if (tmpDDL != null)
            {
               this.Label1.Text=tmpDDL.SelectedItem.Text;
             }
    }

I have tested the code but it should work

Sammy
0
 

Author Comment

by:doolinn
ID: 17848409

sorry but adding an if statement to my code still does not invoke the change to the label text. any more thoughts..thanks
0
 

Author Comment

by:doolinn
ID: 17848552
just realised I should have had autopostback = true on the dropdown...whoops.!
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18410337
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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