Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DropDownList in FormView - Show Selected Item in a Label

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 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