R
rn5a
I have a DataGrid named "dgUsers". The OnDeleteCommand event of the
DataGrid invokes a handler named "DeleteUser". The OnUpdateCommand
event of the DataGrid invokes a handler named "UpdateUser". This is the
code:
Sub DeleteUser(ByVal obj As Object, ByVal ea As
DataGridCommandEventArgs)
Response.Write("Index1: " & ea.Item.ItemIndex & "<br>")
Response.Write("Index2: " & dgUsers.EditItemIndex & "<br>")
dgUsers.EditItemIndex = -1
dgUsers.DataBind()
End Sub
Sub UpdateUser(ByVal obj As Object, ByVal ea As
DataGridCommandEventArgs)
Response.Write("Index1: " & ea.Item.ItemIndex & "<br>")
Response.Write("Index2: " & dgUsers.EditItemIndex & "<br>")
dgUsers.EditItemIndex = -1
dgUsers.DataBind()
End Sub
<asp
ataGrid ID="dgUsers" OnDeleteCommand="DeleteUser"
OnUpdateCommand="UpdateUser" runat="server">
<Columns>
'a few BoundColumns come here
<asp:ButtonColumn ButtonType="LinkButton" CommandName="Delete"
HeaderText="DELETE" Text="DELETE"/>
<asp:EditCommandColumn........./>
</Columns
</asp
ataGrid>
For the Update link, I am using the EditCommandColumn of the DataGrid.
Suppose the user first clicks the Update link of the 3rd row in the
DataGrid (i.e. index=2). Both Index1 & Index2 in the "UpdateUser" sub
are 2. After this, the user clicks the "Delete" link (which is a
ButtonColumn in the DataGrid). Now when the page posts, Index1 & Index2
in the "DeleteUser" sub are 2 & -1 respectively.
Now what's the difference between ea.Item.ItemIndex &
dgUsers.EditItemIndex in the "DeleteUser" sub?
DataGrid invokes a handler named "DeleteUser". The OnUpdateCommand
event of the DataGrid invokes a handler named "UpdateUser". This is the
code:
Sub DeleteUser(ByVal obj As Object, ByVal ea As
DataGridCommandEventArgs)
Response.Write("Index1: " & ea.Item.ItemIndex & "<br>")
Response.Write("Index2: " & dgUsers.EditItemIndex & "<br>")
dgUsers.EditItemIndex = -1
dgUsers.DataBind()
End Sub
Sub UpdateUser(ByVal obj As Object, ByVal ea As
DataGridCommandEventArgs)
Response.Write("Index1: " & ea.Item.ItemIndex & "<br>")
Response.Write("Index2: " & dgUsers.EditItemIndex & "<br>")
dgUsers.EditItemIndex = -1
dgUsers.DataBind()
End Sub
<asp
![Big Grin :D :D](/styles/default/custom/smilies/grin.gif)
OnUpdateCommand="UpdateUser" runat="server">
<Columns>
'a few BoundColumns come here
<asp:ButtonColumn ButtonType="LinkButton" CommandName="Delete"
HeaderText="DELETE" Text="DELETE"/>
<asp:EditCommandColumn........./>
</Columns
</asp
![Big Grin :D :D](/styles/default/custom/smilies/grin.gif)
For the Update link, I am using the EditCommandColumn of the DataGrid.
Suppose the user first clicks the Update link of the 3rd row in the
DataGrid (i.e. index=2). Both Index1 & Index2 in the "UpdateUser" sub
are 2. After this, the user clicks the "Delete" link (which is a
ButtonColumn in the DataGrid). Now when the page posts, Index1 & Index2
in the "DeleteUser" sub are 2 & -1 respectively.
Now what's the difference between ea.Item.ItemIndex &
dgUsers.EditItemIndex in the "DeleteUser" sub?