ASP.NET 2.0 equivalent for e.Item.ItemIndex ?

R

RG

Hello,

I'm raising an event in a datagrid when clicking on a deletecommand button.
I want to get the selected value of the datagrid.

In ASP.NET 1.1 I did this whit e.Item.ItemIndex
In ASP.NET 2.0 I can't use this anymore because EventArgs e has only the
properties/methods tostring, Equals, getHashcode and getType.

Does somebody know a solution for this ?

thx,
 
C

CaffieneRush

It should work just the way you're familiar with because
DataGridCommandEventArgs still has the Item property.

Protected Sub dataGrid1_DeleteCommand(ByVal source As Object, ByVal e
As DataGridCommandEventArgs) Handles dataGrid1.DeleteCommand

lbl.Text = "Deleting row number " & e.Item.ItemIndex
myDataView.Delete(e.Item.ItemIndex)
dataGrid1.DataBind

End Sub
 
R

RG

It should work just the way you're familiar with because
DataGridCommandEventArgs still has the Item property.

Protected Sub dataGrid1_DeleteCommand(ByVal source As Object, ByVal e
As DataGridCommandEventArgs) Handles dataGrid1.DeleteCommand

lbl.Text = "Deleting row number " & e.Item.ItemIndex
myDataView.Delete(e.Item.ItemIndex)
dataGrid1.DataBind

End Sub


Hi, this works but e.Item.ItemIndex returns the number of the row in the
datagrid, but not the datakeyfield.
How can i see this ?

thx
 
C

CaffieneRush

Are you asking how to get the primary key value for the row in
question? If you are then use the DataKeys collection property of your
DataGrid.

'Within the DeleteCommand (or ItemCommand event handler and filtering
for the delete command)
datagrid1.DataKeys(e.Item.ItemIndex)
 
R

RG

Are you asking how to get the primary key value for the row in
question? If you are then use the DataKeys collection property of your
DataGrid.

'Within the DeleteCommand (or ItemCommand event handler and filtering
for the delete command)
datagrid1.DataKeys(e.Item.ItemIndex)

thats it yes!

Thanks for the solution
 

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,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top