Reference Datagrid cell contents

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi. I have an asp:ImageButton which appears when a datagrid row is placed in
Edit mode. The button has it's own click event which fires when the button
is clicked. Within the button's click event, I need to reference the
contents of a cell within the record currently in edit mode.

For example...
The datagrid has 3 columns: ID, Name, Picture
When placed in edit mode my asp:ImageButton appears in the Picture column,
and the ID and Name fields become editable. Within the sub that handles the
asp:ImageButton click event, I need to reference the contents of the Name
column.

I've tried...
Dim Name as String
Name = (CType(DataGrid1.Items.Cells(2).Controls(0), TextBox).Text)
Which does not work.

How can I accomplish this? Thanks!
 
Hi Mr. Mike,

You can try following code.

Dim btn As ImageButton = CType(sender, ImageButton)
Dim item As DataGridItem = CType(btn.NamingContainer,
DataGridItem)
Dim Name As String = CType(item.Cells(2).Controls(0),
TextBox).Text

HTH

Elton Wang
(e-mail address removed)
 

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