Finding the delete button in a datagrid

H

hansiman

When I want to add a js confirm box to a delete button that is
positioned in the last column in a datagrid row I do the following in
the ItemDataBound event:

Dim delBtn As LinkButton = e.Item.Cells(10).Controls(0)
delBtn.Attributes("onclick") = "javascript:return confirm('you
sure?');"

If I want to change an image in a datagrid row I do the following in
the ItemDataBound event:

Dim imgX As System.Web.UI.WebControls.Image =
CType(e.Item.FindControl("imgX"), System.Web.UI.WebControls.Image)
imgX.ImageUrl = "image.gif"

If I add a new column to the grid the reference using the cell number
breaks (e.Item.Cells(10).Controls(0) is now
e.Item.Cells(11).Controls(0)). The reference using the FindControl
method off course still works.

Is there a way to reference the Delete button so that adding new
columns don't break the code?

/M
 
D

dan.c.roth

Hi

A simple solution would be just to use the fact that you know that the
"delete column" is the last column.

That is:

Count - 1

Regards,

Daniel Roth
MCSD.NET
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top