Difference

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:DataGrid 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:DataGrid>

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?
 

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

Similar Threads

Controls? 15
Dynamic BoundColumn 2
Controls 3
DataGrid Edit Problem 9
OnItemCreated? 1
DropDownList DataGrid 1
BoundColumn TextBox 2
Hide/Show EditCommandColumn In DataGrid 0

Top