Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataList
Message
 
General information
Forum:
ASP.NET
Category:
Other
Title:
Miscellaneous
Thread ID:
01059358
Message ID:
01059361
Views:
12
I figured it out, this is what I was missing:
e.Item.ItemType == ListItemType.EditItem
if(( e.Item.ItemType == ListItemType.Header) || (e.Item.ItemType == ListItemType.Footer) || e.Item.ItemType == ListItemType.EditItem )
return;
>Hi all,
>
>I have a webform with a datalist. This dalist has a label and two buttons: btnEdit and btnDelete which allows to edit and delete, both buttons are working fine.
>What I wanted is to add a confirmation for deletion (javascript), so I place this piece of code in the ItemDataBound event of the datalist:
>
>private void datIata_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
>
>{
>   Button btnDelete;
>   if(( e.Item.ItemType == ListItemType.Header) || (e.Item.ItemType ==
>			ListItemType.Footer))
>			return;
>   btnDelete = (Button) e.Item.FindControl("btnDelete");	
>   btnDelete.Attributes.Add("onclick","return confirmDelete();");	
>}
>
>this is the function ConfirmDelete (.js file):
>
>function confirmDelete()
>{
>  var x = confirm("Are you sure you want delete record?");
>  if (x)
>  {
>	return true;
>  }
>  else
>  {
>    return false;
>  }
>}	
>
>The deletion is working fine, is showing the confirmation window BUT if I try to edit I got this error:
>
>Object reference not set to an instance of an object.
>Stack Trace:
>
>
>[NullReferenceException: Object reference not set to an instance of an object.]
>   WebTkt.Tickets.Iata.datIata_ItemDataBound(Object sender, DataListItemEventArgs e) +71
>   System.Web.UI.WebControls.DataList.OnItemDataBound(DataListItemEventArgs e) +110
>   System.Web.UI.WebControls.DataList.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +139
>   System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean useDataSource) +686
>   System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +49
>   System.Web.UI.WebControls.BaseDataList.DataBind() +23
>...
>
>
>Any ideas/suggestions will be much appreciated.
>
>Thanks.
Previous
Reply
Map
View

Click here to load this message in the networking platform