?
Solved

DropDownList in FormView - Show Selected Item in a Label

Posted on 2006-11-01
5
Medium Priority
?
1,117 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 Ageil
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month8 days, 9 hours left to enroll

764 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