?
Solved

Add javascript confirm to linkbutton in nested Datalist

Posted on 2004-11-21
4
Medium Priority
?
469 Views
Last Modified: 2008-02-01
I have a "Delete" linkbutton in edititem of a  nested datalist that I'm trying to add a javascript confirm to on the itemcreated event handler I keep getting "Object reference not set to an instance of an object." I can't seem to find the control.
I'm sure this is simple but its been driving me nuts!!

Thanks in advance
Glorfindal


// "OrderList" Datatlist  is nested in the selected item of the "CustomerList" Datalist

OrderList.ItemCreated += new DataListItemEventHandler(this.Item_Created);

private void Item_Created(Object Sender,  System.Web.UI.WebControls.DataListItemEventArgs e)
{
      if (e.Item.ItemType == ListItemType.EditItem)
      {
                  LinkButton _ApproveBtn = (LinkButton)e.Item.FindControl("btnDelete");
                 _ApproveBtn.Attributes.Add("onClick", "return confirm('Do you wish to delete this order?')");
                        
      }
}
0
Comment
Question by:glorfindal
  • 2
4 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 12645914
try this:

void ItemDataBound(Object Sender,  System.Web.UI.WebControls.DataListItemEventArgs e)
{
     if (e.Item.ItemType == ListItemType.EditItem)
     {
                  LinkButton _ApproveBtn = (LinkButton)e.Item.FindControl("btnDelete");
                 _ApproveBtn.Attributes.Add("onClick", "return confirm('Do you wish to delete this order?')");
                   
     }
}
0
 
LVL 35

Accepted Solution

by:
YZlat earned 2000 total points
ID: 12645926
sorry, I meant

void MyDataList_ItemDataBound(Object Sender,  System.Web.UI.WebControls.DataListItemEventArgs e)
{
     if (e.Item.ItemType == ListItemType.EditItem)
     {
                  LinkButton _ApproveBtn = (LinkButton)e.Item.FindControl("btnDelete");
                 _ApproveBtn.Attributes.Add("onClick", "return confirm('Do you wish to delete this order?')");
                   
     }
}

0
 
LVL 7

Expert Comment

by:smolam
ID: 12646838
I am assuming that you are not using a Template Comlumn in which case the syntax would be as follows, if not then I apologize.

OrderList.ItemCreated += new DataListItemEventHandler(this.Item_Created);

private void Item_Created(Object Sender,  System.Web.UI.WebControls.DataListItemEventArgs e)
{
     if (e.Item.ItemType == ListItemType.EditItem)
     {
                  LinkButton _ApproveBtn = e.Item.Cells[0].Controls[0];
                 _ApproveBtn.Attributes.Add("onClick", "return confirm('Do you wish to delete this order?')");
                   
     }
}

Assuming that the delete column is the first column in your datagrid if not then you need to change the Cells[0] to the index of the column that you have the delete button in?
0
 

Author Comment

by:glorfindal
ID: 12647939
YZlat,

Thanks, That did it. I was close.

 By the way smolam it was a template column but I appreciate the reply

Take care,
Glorfindal

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

809 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