|
 |
aspx thread: Assigning the value of a Label control within a DataList control
using FindControl
Message #1 by "Oliver, Wells" <WOliver@l...> on Tue, 27 Aug 2002 09:19:43 -0700
|
|
The following does not work:
testRequest.FindControl ("completedBy").Text = Session ("LOGON_NAME")
It returns the error "BC30456: 'Text' is not a member of
'System.Web.UI.Control'."
How can the text value of a label control w/in a datalist control be
reassigned?
Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com
Message #2 by Imar Spaanjaars <Imar@S...> on Tue, 27 Aug 2002 18:38:21 +0200
|
|
Hi Oliver,
You'll need to cast the control returned by the FindControl to a specific
control. FindControl returns a Control which does not have a Text property.
Some inherited controls, like the textbox DO have a text property, so
you'll need to cast it to the type you're expecting.
Try this:
CType(testRequest.FindControl("completedBy"), TextBox).Text = Session
("LOGON_NAME")
HtH
Imar
At 09:19 AM 8/27/2002 -0700, you wrote:
>The following does not work:
>
>testRequest.FindControl ("completedBy").Text = Session ("LOGON_NAME")
>
>It returns the error "BC30456: 'Text' is not a member of
>'System.Web.UI.Control'."
>
>How can the text value of a label control w/in a datalist control be
>reassigned?
>
>Wells Oliver
>Web Application Programmer
>Leviton Voice & Data
>xxx-xxx-xxxx
>http://www.levitonvoicedata.com
Message #3 by "Oliver, Wells" <WOliver@l...> on Tue, 27 Aug 2002 09:45:29 -0700
|
|
Thanks for the response. I tried doing this prior to posting but it returns
this error:
"System.NullReferenceException: Object reference not set to an instance of
an object."
I even added "Protected completedBy as Label" (the control is a label) at
the top, but no go. I think it's because it's part of a control. Any ideas?
-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: Tuesday, August 27, 2002 9:38 AM
To: ASP+
Subject: [aspx] Re: Assigning the value of a Label control within a DataList
control using FindControl
Hi Oliver,
You'll need to cast the control returned by the FindControl to a specific
control. FindControl returns a Control which does not have a Text property.
Some inherited controls, like the textbox DO have a text property, so
you'll need to cast it to the type you're expecting.
Try this:
CType(testRequest.FindControl("completedBy"), TextBox).Text = Session
("LOGON_NAME")
HtH
Imar
At 09:19 AM 8/27/2002 -0700, you wrote:
>The following does not work:
>
>testRequest.FindControl ("completedBy").Text = Session ("LOGON_NAME")
>
>It returns the error "BC30456: 'Text' is not a member of
>'System.Web.UI.Control'."
>
>How can the text value of a label control w/in a datalist control be
>reassigned?
>
>Wells Oliver
>Web Application Programmer
>Leviton Voice & Data
>xxx-xxx-xxxx
>http://www.levitonvoicedata.com
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
Message #4 by Imar Spaanjaars <Imar@S...> on Tue, 27 Aug 2002 19:44:21 +0200
|
|
What is testRequest in your case??
I used the same principle in some code and had to use FindControl on an
item of the items collection of a datagrid.
For example:
For Each item In Repeater1.Items
CType(item.FindControl("completedBy"), TextBox).Text = Session
End If
Make sure that testRequest is referencing an item, and not for instance the
Page object.
HtH
Imar
At 09:45 AM 8/27/2002 -0700, you wrote:
>Thanks for the response. I tried doing this prior to posting but it returns
>this error:
>
>"System.NullReferenceException: Object reference not set to an instance of
>an object."
>
>I even added "Protected completedBy as Label" (the control is a label) at
>the top, but no go. I think it's because it's part of a control. Any ideas?
>
>-----Original Message-----
>From: Imar Spaanjaars [mailto:Imar@S...]
>Sent: Tuesday, August 27, 2002 9:38 AM
>To: ASP+
>Subject: [aspx] Re: Assigning the value of a Label control within a DataList
>control using FindControl
>
>
>Hi Oliver,
>
>You'll need to cast the control returned by the FindControl to a specific
>control. FindControl returns a Control which does not have a Text property.
>Some inherited controls, like the textbox DO have a text property, so
>you'll need to cast it to the type you're expecting.
>
>Try this:
>
>CType(testRequest.FindControl("completedBy"), TextBox).Text = Session
>("LOGON_NAME")
>
>
>HtH
>
>Imar
>
>
>At 09:19 AM 8/27/2002 -0700, you wrote:
> >The following does not work:
> >
> >testRequest.FindControl ("completedBy").Text = Session ("LOGON_NAME")
> >
> >It returns the error "BC30456: 'Text' is not a member of
> >'System.Web.UI.Control'."
> >
> >How can the text value of a label control w/in a datalist control be
> >reassigned?
> >
> >Wells Oliver
> >Web Application Programmer
> >Leviton Voice & Data
> >xxx-xxx-xxxx
> >http://www.levitonvoicedata.com
>
>
>
>---
>
>ASP.NET 1.0 Namespace Reference with C#
>http://www.wrox.com/acon11.asp?ISBN=1861007442
>
>ASP.NET 1.0 Namespace Reference with VB.NET
>http://www.wrox.com/acon11.asp?ISBN=1861007450
>
>These books are a complete reference to the ASP.NET namespaces
>for developers who are already familiar with using ASP.NET.
>There is no trivial introductory material or useless .NET
>hype and the presentation of the namespaces, in an easy-to use
>alphabetical order ensures a user-friendly reference format.
>We provide in-depth coverage of all the major ASP.NET classes,
>giving you those real-world tips that the documentation doesn't
>offer, and demonstrating complex techniques with simple
>examples.
Message #5 by "Oliver, Wells" <WOliver@l...> on Tue, 27 Aug 2002 13:57:45 -0700
|
|
testRequest is a dataList. In my edit item template I have a label control
with an id of "completedBy". My doItemEdit () routine (which handles
switching the datalist to edit mode) looks as follows:
Public Sub DoItemEdit (S as System.Object, E as
DataListCommandEventArgs)
' Edit the record
CType (E.Item.FindControl("completedBy"), Label).Text
Session ("LOGON_NAME")
testRequest.EditItemIndex = E.Item.ItemIndex
BindData ()
End Sub
Every time I try to hit this I get a compile error of
"System.NullReferenceException: Object reference not set to an instance of
an object." with the CType line highlighted.
This is causing me endless chagrin :)
-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: Tuesday, August 27, 2002 10:44 AM
To: ASP+
Subject: [aspx] Re: Assigning the value of a Label control within a Da
taList control using FindControl
What is testRequest in your case??
I used the same principle in some code and had to use FindControl on an
item of the items collection of a datagrid.
For example:
For Each item In Repeater1.Items
CType(item.FindControl("completedBy"), TextBox).Text = Session End
If
Make sure that testRequest is referencing an item, and not for instance the
Page object.
HtH
Imar
At 09:45 AM 8/27/2002 -0700, you wrote:
>Thanks for the response. I tried doing this prior to posting but it
>returns this error:
>
>"System.NullReferenceException: Object reference not set to an instance
>of an object."
>
>I even added "Protected completedBy as Label" (the control is a label)
>at the top, but no go. I think it's because it's part of a control. Any
>ideas?
>
>-----Original Message-----
>From: Imar Spaanjaars [mailto:Imar@S...]
>Sent: Tuesday, August 27, 2002 9:38 AM
>To: ASP+
>Subject: [aspx] Re: Assigning the value of a Label control within a
>DataList control using FindControl
>
>
>Hi Oliver,
>
>You'll need to cast the control returned by the FindControl to a
>specific control. FindControl returns a Control which does not have a
>Text property. Some inherited controls, like the textbox DO have a text
>property, so you'll need to cast it to the type you're expecting.
>
>Try this:
>
>CType(testRequest.FindControl("completedBy"), TextBox).Text = Session
>("LOGON_NAME")
>
>
>HtH
>
>Imar
>
>
>At 09:19 AM 8/27/2002 -0700, you wrote:
> >The following does not work:
> >
> >testRequest.FindControl ("completedBy").Text = Session ("LOGON_NAME")
> >
> >It returns the error "BC30456: 'Text' is not a member of
> >'System.Web.UI.Control'."
> >
> >How can the text value of a label control w/in a datalist control be
> >reassigned?
> >
> >Wells Oliver
> >Web Application Programmer
> >Leviton Voice & Data
> >xxx-xxx-xxxx
> >http://www.levitonvoicedata.com
>
>
>
>---
>
>ASP.NET 1.0 Namespace Reference with C#
>http://www.wrox.com/acon11.asp?ISBN=1861007442
>
>ASP.NET 1.0 Namespace Reference with VB.NET
>http://www.wrox.com/acon11.asp?ISBN=1861007450
>
>These books are a complete reference to the ASP.NET namespaces for
>developers who are already familiar with using ASP.NET. There is no
>trivial introductory material or useless .NET hype and the presentation
>of the namespaces, in an easy-to use alphabetical order ensures a
>user-friendly reference format. We provide in-depth coverage of all the
>major ASP.NET classes, giving you those real-world tips that the
>documentation doesn't offer, and demonstrating complex techniques with
>simple examples.
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
Message #6 by Imar Spaanjaars <Imar@S...> on Tue, 27 Aug 2002 23:08:12 +0200
|
|
Does your label control have a runat=3D"server" attribute and an ID??
AFAIK, this should work the way it's supposed to be.....
Not sure if it helps, but this is what the MSDN says about it:
Create a method for the UpdateCommand event that reads the values of the
editing controls in the current item and writes them back to the data
source.
=B7 Bound columns The e.Item property contains an indexed Cells
collection that contains one Cell object for each column in the DataGrid
control. The data is found in the first control in the Controls collection
of the cell. The following statements retrieve the string data from the
TextBox control displayed in the second column:
' Visual Basic
Dim newData As String
Dim aTextBox As TextBox
aTextBox =3D CType(e.Item.Cells(1).Controls(0), TextBox)
newData =3D aTextBox.Text
=B7 Template columns The e.Item property contains an indexed Cells
collection that contains one Cell for each column in the DataGrid. The data
is contained in controls you created while editing the template. Use the
FindControl method and the control's name to retrieve the data. The
following statements retrieve the string data from the TextBox control with
Name property "FirstName" in the second column:
' Visual Basic
Dim newName As String
Dim box As TextBox
box =3D CType(e.Item.Cells(1).FindControl("FirstName"), TextBox)
newName =3D box.text
Are you using a Bound Column instead of a template column? If so, try using
the Controls(0) indexer instead of the Find Control
Imar
At 01:57 PM 8/27/2002 -0700, you wrote:
>testRequest is a dataList. In my edit item template I have a label control
>with an id of "completedBy". My doItemEdit () routine (which handles
>switching the datalist to edit mode) looks as follows:
>
> Public Sub DoItemEdit (S as System.Object, E as
>DataListCommandEventArgs)
> ' Edit the record
> CType (E.Item.FindControl("completedBy"), Label).Text =3D
>Session ("LOGON_NAME")
>
> testRequest.EditItemIndex =3D E.Item.ItemIndex
> BindData ()
> End Sub
>
>Every time I try to hit this I get a compile error of
>"System.NullReferenceException: Object reference not set to an instance of
>an object." with the CType line highlighted.
>
>This is causing me endless chagrin :)
>
>-----Original Message-----
>From: Imar Spaanjaars [mailto:Imar@S...]
>Sent: Tuesday, August 27, 2002 10:44 AM
>To: ASP+
>Subject: [aspx] Re: Assigning the value of a Label control within a Da
>taList control using FindControl
>
>
>What is testRequest in your case??
>
>I used the same principle in some code and had to use FindControl on an
>item of the items collection of a datagrid.
>For example:
>
>For Each item In Repeater1.Items
> CType(item.FindControl("completedBy"), TextBox).Text =3D Session
End
>If
>
>Make sure that testRequest is referencing an item, and not for instance the
>Page object.
>
>HtH
>
>
>Imar
>
>
>
>At 09:45 AM 8/27/2002 -0700, you wrote:
> >Thanks for the response. I tried doing this prior to posting but it
> >returns this error:
> >
> >"System.NullReferenceException: Object reference not set to an instance
> >of an object."
> >
> >I even added "Protected completedBy as Label" (the control is a label)
> >at the top, but no go. I think it's because it's part of a control. Any
> >ideas?
> >
> >-----Original Message-----
> >From: Imar Spaanjaars [mailto:Imar@S...]
> >Sent: Tuesday, August 27, 2002 9:38 AM
> >To: ASP+
> >Subject: [aspx] Re: Assigning the value of a Label control within a
> >DataList control using FindControl
> >
> >
> >Hi Oliver,
> >
> >You'll need to cast the control returned by the FindControl to a
> >specific control. FindControl returns a Control which does not have a
> >Text property. Some inherited controls, like the textbox DO have a text
> >property, so you'll need to cast it to the type you're expecting.
> >
> >Try this:
> >
> >CType(testRequest.FindControl("completedBy"), TextBox).Text =3D Session
> >("LOGON_NAME")
> >
> >
> >HtH
> >
> >Imar
> >
> >
> >At 09:19 AM 8/27/2002 -0700, you wrote:
> > >The following does not work:
> > >
> > >testRequest.FindControl ("completedBy").Text =3D Session ("LOGON_NAME")
> > >
> > >It returns the error "BC30456: 'Text' is not a member of
> > >'System.Web.UI.Control'."
> > >
> > >How can the text value of a label control w/in a datalist control be
> > >reassigned?
> > >
> > >Wells Oliver
> > >Web Application Programmer
> > >Leviton Voice & Data
> > >xxx-xxx-xxxx
> > >http://www.levitonvoicedata.com
> >
> >
> >
> >---
> >
> >ASP.NET 1.0 Namespace Reference with C#
> >http://www.wrox.com/acon11.asp?ISBN=3D1861007442
> >
> >ASP.NET 1.0 Namespace Reference with VB.NET
> >http://www.wrox.com/acon11.asp?ISBN=3D1861007450
> >
> >These books are a complete reference to the ASP.NET namespaces for
> >developers who are already familiar with using ASP.NET. There is no
> >trivial introductory material or useless .NET hype and the presentation
> >of the namespaces, in an easy-to use alphabetical order ensures a
> >user-friendly reference format. We provide in-depth coverage of all the
> >major ASP.NET classes, giving you those real-world tips that the
> >documentation doesn't offer, and demonstrating complex techniques with
> >simple examples.
>
>
>
>---
>
>ASP.NET 1.0 Namespace Reference with C#
>http://www.wrox.com/acon11.asp?ISBN=3D1861007442
>
>ASP.NET 1.0 Namespace Reference with VB.NET
>http://www.wrox.com/acon11.asp?ISBN=3D1861007450
>
>These books are a complete reference to the ASP.NET namespaces
>for developers who are already familiar with using ASP.NET.
>There is no trivial introductory material or useless .NET
>hype and the presentation of the namespaces, in an easy-to use
>alphabetical order ensures a user-friendly reference format.
>We provide in-depth coverage of all the major ASP.NET classes,
>giving you those real-world tips that the documentation doesn't
>offer, and demonstrating complex techniques with simple
>examples.
>
>---
>
>
>---
>
>ASP.NET 1.0 Namespace Reference with C#
>http://www.wrox.com/acon11.asp?ISBN=3D1861007442
>
>ASP.NET 1.0 Namespace Reference with VB.NET
>http://www.wrox.com/acon11.asp?ISBN=3D1861007450
>
>These books are a complete reference to the ASP.NET namespaces
>for developers who are already familiar with using ASP.NET.
>There is no trivial introductory material or useless .NET
>hype and the presentation of the namespaces, in an easy-to use
>alphabetical order ensures a user-friendly reference format.
>We provide in-depth coverage of all the major ASP.NET classes,
>giving you those real-world tips that the documentation doesn't
>offer, and demonstrating complex techniques with simple
>examples.
>
>---
Message #7 by "Andrew Bradnan" <andrew@w...> on Tue, 27 Aug 2002 14:47:58 -0700
|
|
You are looking for the sub-control on the _Page_, not in the =3D
DataListItem. You might only have one item in the list, but the data
=3D
list is going to assume there are multiple items.
DataList NewDL =3D3D
(DataList)this.DataList1.FindControl("DataList2");
This should work. This is looking in the DataListItem.
DataList NewDL =3D3D (DataList)e.Item.FindControl("DataList2");
Hope that helps,
Andrew
http://whirly.info
.NET forums, stop by and visit us.
-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: Tuesday, August 27, 2002 9:20 AM
To: ASP+
Subject: [aspx] Assigning the value of a Label control within a DataList
control using FindControl
The following does not work:
testRequest.FindControl ("completedBy").Text =3D Session ("LOGON_NAME")
It returns the error "BC30456: 'Text' is not a member of
'System.Web.UI.Control'."
How can the text value of a label control w/in a datalist control be
reassigned?
Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=3D1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=3D1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
Message #8 by "Andrew Bradnan" <andrew@w...> on Tue, 27 Aug 2002 14:51:11 -0700
|
|
:$
Well, that last message should confuse everyone (it bounced my reply
earlier and I re-responded to the wrong email).
One more time....
Remember there is going to be a textbox in every Item of the DataList.
"Normally", you'd do a FindControl during an ItemCreated or =3D
ItemDataBound event.
public void OnItemCreated(Object sender, DataListItemEventArgs e)
{
TextBox t =3D3D (TextBox)e.Item.FindControl("completedBy");
t.Text =3D3D Session["LOGON_NAME"];
.....
}
If it's a bound column, then it may just get overwritten by the data =3D
binding :(
You could probably loop through them all in Page_PreRender(), which is
=3D
after all the events
myDataList.Item[0].FindControl("completedBy")
Hope that helps,
Andrew
http://whirly.info
.NET forums, stop by and visit us
-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: Tuesday, August 27, 2002 9:20 AM
To: ASP+
Subject: [aspx] Assigning the value of a Label control within a DataList
control using FindControl
The following does not work:
testRequest.FindControl ("completedBy").Text =3D Session ("LOGON_NAME")
It returns the error "BC30456: 'Text' is not a member of
'System.Web.UI.Control'."
How can the text value of a label control w/in a datalist control be
reassigned?
Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=3D1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=3D1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
Message #9 by "Oliver, Wells" <WOliver@l...> on Tue, 27 Aug 2002 14:55:39 -0700
|
|
Hmm, but I am trying to use FindControl to actually change the text property
of the found control, not just read it.
e.g:
Public Sub DoItemEdit (S as System.Object, E as
DataListCommandEventArgs)
' Edit the record
CType (E.Item.FindControl("completedDate"), Label).Text
"This breaks"
testRequest.EditItemIndex = E.Item.ItemIndex
BindData ()
End Sub
'testRequest' is a dataList, and the "completedDate" is a label control that
is _only_ in the EditItemTemplate, not in the ItemTemplate.
Gives me the "System.NullReferenceException: Object reference not set to an
instance of an object." on the CTYpe line every time when I go into edit
mode. I'm dumbfounded...
-----Original Message-----
From: Andrew Bradnan [mailto:andrew@w...]
Sent: Tuesday, August 27, 2002 2:51 PM
To: ASP+
Subject: [aspx] RE: Assigning the value of a Label control within a DataList
control using FindControl
:$
Well, that last message should confuse everyone (it bounced my reply earlier
and I re-responded to the wrong email). One more time....
Remember there is going to be a textbox in every Item of the DataList.
"Normally", you'd do a FindControl during an ItemCreated or = ItemDataBound
event.
public void OnItemCreated(Object sender, DataListItemEventArgs e) {
TextBox t =3D (TextBox)e.Item.FindControl("completedBy");
t.Text =3D Session["LOGON_NAME"];
.....
}
If it's a bound column, then it may just get overwritten by the data
binding :(
You could probably loop through them all in Page_PreRender(), which is
after all the events
myDataList.Item[0].FindControl("completedBy")
Hope that helps,
Andrew
http://whirly.info
.NET forums, stop by and visit us
-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: Tuesday, August 27, 2002 9:20 AM
To: ASP+
Subject: [aspx] Assigning the value of a Label control within a DataList
control using FindControl
The following does not work:
testRequest.FindControl ("completedBy").Text = Session ("LOGON_NAME")
It returns the error "BC30456: 'Text' is not a member of
'System.Web.UI.Control'."
How can the text value of a label control w/in a datalist control be
reassigned?
Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
Message #10 by "Andrew Bradnan" <andrew@w...> on Tue, 27 Aug 2002 15:57:33 -0700
|
|
Here's an example. Cut-n-paste into an aspx file and it will run. Or
just click.
http://whirly.info/examples/editlabel.aspx
There's a label in the EditItemTemplate that I change when you click
edit.
Hope that's what you need.
Andrew
<script language=3D"c#" runat=3Dserver>
class Something
{
public string Test
{ get { return "test attribute"; }}
}
=09
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
Bind();
}
private void Bind()
{
ArrayList a =3D new ArrayList();
a.Add(new Something());
a.Add(new Something());
a.Add(new Something());
a.Add(new Something());
=09
myDataList.DataSource =3D a;
myDataList.DataBind();
}
=09
public void OnEditCommand(object sender, DataListCommandEventArgs e)
{
myDataList.EditItemIndex =3D e.Item.ItemIndex;
Bind();
}
public void EditItemCreated(Object sender, DataListItemEventArgs e)
{
ListItemType lit =3D e.Item.ItemType;
if (lit =3D=3D ListItemType.EditItem)
{
Label t =3D (Label)e.Item.FindControl("user");
t.Text =3D "Label number " + myDataList.EditItemIndex;
}
}
=09
</script>
<html>
<head>
<title>WebForm1</title>
</head>
<body>
=09
<form runat=3Dserver>
<asp:DataList ID=3D"myDataList" Runat=3Dserver
OnEditCommand=3D"OnEditCommand" OnItemCreated=3D"EditItemCreated">
<ItemTemplate>
<asp:LinkButton CssClass=3D"white" Runat=3D"server"
CommandName=3D"Edit" ID=3D"Linkbutton1"
NAME=3D"Linkbutton1">Edit</asp:LinkButton>
<%# DataBinder.Eval(Container.DataItem, "Test") %><br>
</ItemTemplate>
<EditItemTemplate>
<span style=3D"background-color:#94a2ba;"> Now in Edit Mode.
<asp:Label ID=3D"user" Runat=3Dserver>Old Label</asp:Label>
<asp:Textbox runat=3Dserver value=3D<%#
DataBinder.Eval(Container.DataItem, "Test") %> /></span>
</EditItemTemplate>
</asp:DataList>
</form>
Back to <a href=3D"http://whirly.info">Whirly.Info</a>
</body>
</html>
-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: Tuesday, August 27, 2002 2:56 PM
To: ASP+
Subject: [aspx] RE: Assigning the value of a Label control within a Da
taList control using FindControl
Hmm, but I am trying to use FindControl to actually change the text
property
of the found control, not just read it.
e.g:
Public Sub DoItemEdit (S as System.Object, E as
DataListCommandEventArgs)
' Edit the record
CType (E.Item.FindControl("completedDate"), Label).Text =3D
"This breaks"
testRequest.EditItemIndex =3D E.Item.ItemIndex
BindData ()
End Sub
'testRequest' is a dataList, and the "completedDate" is a label control
that
is _only_ in the EditItemTemplate, not in the ItemTemplate.
Gives me the "System.NullReferenceException: Object reference not set to
an
instance of an object." on the CTYpe line every time when I go into edit
mode. I'm dumbfounded...
-----Original Message-----
From: Andrew Bradnan [mailto:andrew@w...]
Sent: Tuesday, August 27, 2002 2:51 PM
To: ASP+
Subject: [aspx] RE: Assigning the value of a Label control within a
DataList
control using FindControl
:$
Well, that last message should confuse everyone (it bounced my reply
earlier
and I re-responded to the wrong email). One more time....
Remember there is going to be a textbox in every Item of the DataList.
"Normally", you'd do a FindControl during an ItemCreated or =3D
ItemDataBound
event.
public void OnItemCreated(Object sender, DataListItemEventArgs e) {
TextBox t =3D3D (TextBox)e.Item.FindControl("completedBy");
t.Text =3D3D Session["LOGON_NAME"];
.....
}
If it's a bound column, then it may just get overwritten by the data =3D
binding :(
You could probably loop through them all in Page_PreRender(), which is
=3D
after all the events
myDataList.Item[0].FindControl("completedBy")
Hope that helps,
Andrew
http://whirly.info
.NET forums, stop by and visit us
-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: Tuesday, August 27, 2002 9:20 AM
To: ASP+
Subject: [aspx] Assigning the value of a Label control within a DataList
control using FindControl
The following does not work:
testRequest.FindControl ("completedBy").Text =3D Session ("LOGON_NAME")
It returns the error "BC30456: 'Text' is not a member of
'System.Web.UI.Control'."
How can the text value of a label control w/in a datalist control be
reassigned?
Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=3D1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=3D1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=3D1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=3D1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=3D1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=3D1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
|
|
 |