Hello, I am trying to delete a colum from a datatable which is displayed in a datagrid. when I excecute the code, it shows the error, there is no row at position 0(if i try to delete the first row, if 2nd row, it says "no rows at postion 2"). but I check the row.count method and it returns the number of rows in the table. still i get the error saying "there is no row at the corresponding postion. My code as follows
MyDatatable.aspx
<asp:DataGrid ID="Dg" runat="server" OnDeleteCommand ="Dg_DeleteCommand" >
<Columns><asp:ButtonColumn CommandName="Delete" Text="Remove Item"></asp:ButtonColumn></Columns>
</asp:DataGrid>
MyTable.aspx.
vb(code behind file)
Protected Sub Dg_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles Dg.DeleteCommand
objDT = Session("MyTable")
Dim index As Integer
If objDT.Rows.Count >= 0 Then
index = objDT.Rows.Count
objDT.Rows.Item(index).Delete()
Else
response.write("No rows in the tabel")
End If
Session("Mytable") = objDT
Dg.DataSource = objDT
Dg.DataBind()