Solved

DropDownList in FormView - Show Selected Item in a Label

Posted on 2006-11-01
5
1,093 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
  • 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

16 Experts available now in Live!

Get 1:1 Help Now