List Info

Thread: Finding Control on Details View




Finding Control on Details View
user name
2007-01-26 12:19:18
I have been trying to find a solution for the following: I
have a 
DropDownList with values New, Approved, Declined with
respective 0,1,2. I 
have a label that represents these numbers but I want to
read the 
description not the value on the DB

Protected Sub DetailsView2_ItemUpdated(ByVal sender As
Object, ByVal e As 
System.Web.UI.WebControls.DetailsViewUpdatedEventArgs)
        Dim ddlApproval As DropDownList = 
CType(DetailsView2.FindControl("DropDownList1"),
DropDownList)
        Dim lblApproval As Label =
CType(DetailsView2.FindControl("Label1"), 
Label)
        If ddlApproval.SelectedIndex = "0" Then
            lblApproval.Text = "New"
        Else
            Response.Write("Hello")
        End If
    End Sub
When I run the above sub I get the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the
execution of the 
current web request. Please review the stack trace for more
information 
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object
reference not set 
to an instance of an object.

Source Error:


Line 13:         Dim lblApproval As Label = 
CType(DetailsView2.FindControl("Label1"), Label)
Line 14:         If ddlApproval.SelectedIndex =
"0" Then
Line 15:             lblApproval.Text = "New"
Line 16:         Else
Line 17:             Response.Write("Hello")


Where at Line 15 throws the error

I have only one label control and is called
"Label1"
what I am doing wrong.... Any hep will be appreciated


Carlos

____________________________________________________________
_____
Check out all that glitters with the MSN Entertainment Guide
to the Academy 
Awards?   http://movies.msn.com/movies/oscars2007/?icid=ncosc
artagline2



Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com

RE: Finding Control on Details View
user name
2007-01-26 14:02:45
Also, you might try DetailsView2_ItemUpdating as apposed to
DetailsView2_ItemUpdated. 

I haven't really used the DetailsView but in a GridView you
would use
RowUpdating not RowUpdated. 

Hth,
David



-----Original Message-----
From: Carlos Ramon Lopez Midence [mailto:caralomihotmail.com] 
Sent: Friday, January 26, 2007 12:19 PM
To: aspnet-datadisplaycontrolsaspadvice.com
Subject: [aspnet-datadisplaycontrols] Finding Control on
Details View

I have been trying to find a solution for the following: I
have a 
DropDownList with values New, Approved, Declined with
respective 0,1,2. I 
have a label that represents these numbers but I want to
read the 
description not the value on the DB

Protected Sub DetailsView2_ItemUpdated(ByVal sender As
Object, ByVal e As 
System.Web.UI.WebControls.DetailsViewUpdatedEventArgs)
        Dim ddlApproval As DropDownList = 
CType(DetailsView2.FindControl("DropDownList1"),
DropDownList)
        Dim lblApproval As Label =
CType(DetailsView2.FindControl("Label1"),

Label)
        If ddlApproval.SelectedIndex = "0" Then
            lblApproval.Text = "New"
        Else
            Response.Write("Hello")
        End If
    End Sub
When I run the above sub I get the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the
execution of the 
current web request. Please review the stack trace for more
information 
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object
reference not set 
to an instance of an object.

Source Error:


Line 13:         Dim lblApproval As Label = 
CType(DetailsView2.FindControl("Label1"), Label)
Line 14:         If ddlApproval.SelectedIndex =
"0" Then
Line 15:             lblApproval.Text = "New"
Line 16:         Else
Line 17:             Response.Write("Hello")


Where at Line 15 throws the error

I have only one label control and is called
"Label1"
what I am doing wrong.... Any hep will be appreciated


Carlos

____________________________________________________________
_____
Check out all that glitters with the MSN Entertainment Guide
to the Academy 
Awards?   http://movies.msn.com/movies/oscars2007/?icid=ncosc
artagline2



Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com





Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )