473,385 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

OnItemCreated Event

I have a DataList and I want to add some Javascript to a button in the Datalist. I am guessing that I will use the "OnItemCreated" event to find my control and then load the java script to the button.

The problem is that I can not find the control when I search for it in the event. I am guessing that internally it is assigning a unique ID to each of the buttons that the Datalist is creating and this is why I can not find the control with a "FindControl" method.

So how do I find the control? Here is the code I created...

if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Control ctrl = e.Item.FindControl("cmdPPIPEditDelete");
if (ctrl != null)
{
((Button)ctrl).Attributes["onclick"] = "return RecordDeleteConfirmation();";
}
}
Nov 18 '05 #1
2 1239
your code looks fine. if you are checking for OR operation (and not bitwise
or) in the code
you can replace | with || .
and make sure that your button id is correct.

hth,
Av.

"Jim Heavey" <Ji*******@discussions.microsoft.com> wrote in message
news:56**********************************@microsof t.com...
I have a DataList and I want to add some Javascript to a button in the
Datalist. I am guessing that I will use the "OnItemCreated" event to find
my control and then load the java script to the button.

The problem is that I can not find the control when I search for it in the
event. I am guessing that internally it is assigning a unique ID to each
of the buttons that the Datalist is creating and this is why I can not
find the control with a "FindControl" method.

So how do I find the control? Here is the code I created...

if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Control ctrl = e.Item.FindControl("cmdPPIPEditDelete");
if (ctrl != null)
{
((Button)ctrl).Attributes["onclick"] = "return
RecordDeleteConfirmation();";
}
}

Nov 18 '05 #2
It is the little things... I guess I was convinced that it would never find the control so I just missed that I had place the wrong name into the FindControl method.

Thanks

"avnrao" wrote:
your code looks fine. if you are checking for OR operation (and not bitwise
or) in the code
you can replace | with || .
and make sure that your button id is correct.

hth,
Av.

"Jim Heavey" <Ji*******@discussions.microsoft.com> wrote in message
news:56**********************************@microsof t.com...
I have a DataList and I want to add some Javascript to a button in the
Datalist. I am guessing that I will use the "OnItemCreated" event to find
my control and then load the java script to the button.

The problem is that I can not find the control when I search for it in the
event. I am guessing that internally it is assigning a unique ID to each
of the buttons that the Datalist is creating and this is why I can not
find the control with a "FindControl" method.

So how do I find the control? Here is the code I created...

if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Control ctrl = e.Item.FindControl("cmdPPIPEditDelete");
if (ctrl != null)
{
((Button)ctrl).Attributes["onclick"] = "return
RecordDeleteConfirmation();";
}
}


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andy Read | last post by:
Hello all, I have the requirement to produce source code that produces an object hierarchy. Example: Root | Folder 1
0
by: Sam | last post by:
Hi, I have a class that receives a DataGrid control and populates it. However, I need to do an OnItemCreated event because if I'm missing data in a certain column, I display a HyperLink control...
0
by: Jim Heavey | last post by:
I have a DataList and I want to add some Javascript to a button in the Datalist. I am guessing that I will use the "OnItemCreated" event to find my control and then load the java script to the...
0
by: Jim Heavey | last post by:
I have a DataList and I want to add some Javascript to a button in the Datalist. I am guessing that I will use the "OnItemCreated" event to find my control and then load the java script to the...
1
by: Mauritsius | last post by:
I have a simple page where I would like to modify a repeater (bounded to a dataset) if a button (outside the repeater) is clicked or not. I tried to solve this with a button click event that...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
9
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the...
1
by: Arpan | last post by:
Consider the following code which populates a DataGrid with the items of a string array: Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If (ViewState("Colors") Is Nothing) Then...
3
by: Arpan | last post by:
A DataGrid displays data from a DataSet. The DataGrid has the OnItemCreated event. Assume that the OnItemCreated event calls a sub named "InEditMode()". The DataGrid gets rendered as soon as this...
1
by: rn5a | last post by:
In the .NET2.0 SDK Documentation, the DataGrid's OnItemCreated method is described as thus: The ItemCreated event is raised when an item in the DataGrid control is created, both during...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.