Click here to Skip to main content
16,008,469 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Question about advancing my programming skills Pin
Mike Ellison24-Apr-06 6:33
Mike Ellison24-Apr-06 6:33 
QuestionOn Line Test Engine Pin
248912824-Apr-06 4:53
248912824-Apr-06 4:53 
AnswerRe: On Line Test Engine Pin
J4amieC24-Apr-06 5:12
J4amieC24-Apr-06 5:12 
Questionusing SQL commands Datagrid control Pin
LAYEEQ AHMED KHAN24-Apr-06 4:42
LAYEEQ AHMED KHAN24-Apr-06 4:42 
AnswerRe: using SQL commands Datagrid control Pin
Mike Ellison24-Apr-06 8:00
Mike Ellison24-Apr-06 8:00 
Question.Net 2.0 & SQLServer 2005 Hosting Pin
VickyC#24-Apr-06 4:38
VickyC#24-Apr-06 4:38 
AnswerRe: .Net 2.0 & SQLServer 2005 Hosting Pin
Mike Ellison24-Apr-06 8:01
Mike Ellison24-Apr-06 8:01 
QuestionPass DropDownList selected value to Label - FindControl problem? Pin
FionaDM24-Apr-06 3:27
FionaDM24-Apr-06 3:27 
I want to pass the value of the selected item in a dropdownlist to a label. The dropdownlist is inside a FormView and
the label is outside in the main form. I'm trying to do this by implementing an event handler for the event
OnSelectedIndexChanged.

I cannot get it to work as I get an error:

Object reference not set to an instance of an object w.r.t code: Label1.Text = myDDL.SelectedItem.Value.ToString();



Here's the ASP/HTML


...
<asp:formview>
....
<insertitemtemplate>
....
<asp:dropdownlist id="DropDownList1" runat="server" datasourceid="SqlDataSource1"
datatextfield="StaffID" datavaluefield="StaffID" selectedvalue="<%# Bind("StaffID") %>" autopostback="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged" ondatabound="DropDownList1_DataBound">

....

....


<

<asp:sqldatasource id="SqlDataSource1" runat="server"
connectionstring="<%$ ConnectionStrings:MyConnectionString %>"
selectcommand="SELECT StaffID FROM Staff_tbl">

...
<asp:label id="Label1" runat="server" text="Label">


Here's the event handler (c#)

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

{
DropDownList myDropDownList = (DropDownList)FindControl("DropDownList1");
Label1.Text = myDropDownList.SelectedItem.Value.ToString();
}

My FindControl clearly isn't doing what I think it should.

I can get this to work if the dropdownlist is not inside a FormView where there is no need to use FindControl.

E.g.

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

{
Label1.Text = DropDownList1.SelectedItem.Value.ToString();
}

But unfortunately I NEED to have the dropdownlist inside a FormView.
Thanks

Majella
AnswerRe: Pass DropDownList selected value to Label - FindControl problem? Pin
Paddy Boyd24-Apr-06 3:37
Paddy Boyd24-Apr-06 3:37 
NewsRe: Pass DropDownList selected value to Label - FindControl problem? Pin
FionaDM24-Apr-06 22:06
FionaDM24-Apr-06 22:06 
AnswerRe: Pass DropDownList selected value to Label - FindControl problem? Pin
Mike Ellison24-Apr-06 8:06
Mike Ellison24-Apr-06 8:06 
Question.NET Framework......... Pin
daviiie24-Apr-06 3:05
daviiie24-Apr-06 3:05 
AnswerRe: .NET Framework......... Pin
daviiie24-Apr-06 3:55
daviiie24-Apr-06 3:55 
QuestionDownload and save File from Web Server Pin
dumser124-Apr-06 2:59
dumser124-Apr-06 2:59 
AnswerRe: Download and save File from Web Server Pin
Paddy Boyd24-Apr-06 4:04
Paddy Boyd24-Apr-06 4:04 
GeneralRe: Download and save File from Web Server Pin
dumser125-Apr-06 2:26
dumser125-Apr-06 2:26 
Questionmultiple configuration files Pin
chakkara200324-Apr-06 2:56
chakkara200324-Apr-06 2:56 
AnswerRe: multiple configuration files Pin
Mike Ellison24-Apr-06 8:17
Mike Ellison24-Apr-06 8:17 
AnswerRe: multiple configuration files Pin
Mike Ellison24-Apr-06 8:23
Mike Ellison24-Apr-06 8:23 
GeneralRe: multiple configuration files Pin
chakkara200324-Apr-06 18:36
chakkara200324-Apr-06 18:36 
GeneralRe: multiple configuration files Pin
chakkara200324-Apr-06 20:07
chakkara200324-Apr-06 20:07 
QuestionMemory Management Pin
MaheshSharma24-Apr-06 2:56
MaheshSharma24-Apr-06 2:56 
AnswerRe: Memory Management Pin
Mike Ellison24-Apr-06 8:11
Mike Ellison24-Apr-06 8:11 
GeneralRe: Memory Management Pin
MaheshSharma24-Apr-06 18:32
MaheshSharma24-Apr-06 18:32 
GeneralRe: Memory Management Pin
Mike Ellison26-Apr-06 6:26
Mike Ellison26-Apr-06 6:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.