Adding Attributes to buttons within datagrid

  • Thread starter Thread starter Craig G
  • Start date Start date
C

Craig G

i was using the following on a serverside button on a form
If (Not Page.IsPostBack) Then

Me.BtnDelete.Attributes.Add("onclick","return confirm('Are you sure you want
to delete?');")

End If

but was wondering how i would go about doing the same for a button within a
column? i cannot see btnDelete in the code-behind page

Cheers,
Craig
 
nice one, never knew about the ItemDataBound event

dim delete as Button = ctype(e.Item.FindControl("btnDelete"), button)

delete.Attributes.Add("onclick", "return confirm('Are you sure you want to
delete?');")

having tried the above, i keep gettin the following error :-

Object reference not set to an instance of an object


Cheers,
Craig
 
delete is nothing..this is possible under a number of circumstances.

dim delete as Button = ctype(e.Item.FindControl("btnDelete"), button)
if not delete is nothing then
delete.Attributes.Add("onclick", "return confirm('Are you sure you want to
delete?');")

end if

You should check for e.Item.ItemType and make sure it's either an
ListItemType.Item or ListItemType.AlternatingItem. ItemDataBound fires even
when the header/footer/paging is being created, in those templates you don't
have a btnDelete, which is why you are getting a null reference. The
tutorial goes over that stuff.

Karl
 
nice one cheers.

Craig

Karl Seguin said:
delete is nothing..this is possible under a number of circumstances.

dim delete as Button = ctype(e.Item.FindControl("btnDelete"), button)
if not delete is nothing then
delete.Attributes.Add("onclick", "return confirm('Are you sure you want to
delete?');")

end if

You should check for e.Item.ItemType and make sure it's either an
ListItemType.Item or ListItemType.AlternatingItem. ItemDataBound fires even
when the header/footer/paging is being created, in those templates you don't
have a btnDelete, which is why you are getting a null reference. The
tutorial goes over that stuff.

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top