Home All Groups Group Topic Archive Search About

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

Author
27 Mar 2006 8:25 PM
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,

Author
27 Mar 2006 8:54 PM
Phillip Williams
Use the ItemCommand event:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.itemcommand(VS.80).aspx

Show quoteHide quote
"RG" wrote:

> 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,
>
>
>
Author
27 Mar 2006 9:04 PM
CaffieneRush@gmail.com
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
Author
28 Mar 2006 8:25 PM
RG
<CaffieneR***@gmail.com> schreef in bericht
news:1143493457.971066.198020@g10g2000cwb.googlegroups.com...
> 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
Author
28 Mar 2006 10:46 PM
CaffieneRush@gmail.com
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)
Author
29 Mar 2006 6:13 PM
RG
<CaffieneR***@gmail.com> schreef in bericht
news:1143586019.764101.193840@t31g2000cwb.googlegroups.com...
> 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