locked
System.IndexOutOfRangeException: There is no row at position 11. RRS feed

  • Question

  • User-836439670 posted
    Hi All, Thanks in advance for your help. I am trying to insert a row to the dataset. My code is as under: Private Sub CategoryGrid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles CategoryGrid.ItemCommand Dim st As String st = e.CommandName Dim NewRecords As DataTable CategoryGrid.EditItemIndex = e.Item.ItemIndex If e.CommandName = "Item" Then Dim anyRow As DataRow = CategoryData1.Categories.NewRow Dim int As Integer anyRow("Description") = "" anyRow("CategoryName") = "" CategoryData1.Categories.Rows.Add(anyRow) int = e.Item.ItemIndex int = int + 1 CategoryGrid.EditItemIndex = int Dim st1 As String = anyRow.RowState Console.Write("AddRow " & anyRow.RowState) CategoryGrid.DataBind() End If But after updating the values in the datagrid when I call update function, it gives me following error: Exception Details: System.IndexOutOfRangeException: There is no row at position 11. Source Error: Line 196: Public Default ReadOnly Property Item(ByVal index As Integer) As CategoriesRow Line 197: Get Line 198: Return CType(Me.Rows(index),CategoriesRow) Line 199: End Get Line 200: End Property Source File: c:\inetpub\wwwroot\testData\CategoryData.vb Line: 198 Stack Trace: [IndexOutOfRangeException: There is no row at position 11.] System.Data.DataRowCollection.get_Item(Int32 index) +63 testData.CategoriesDataTable.get_Item(Int32 index) in c:\inetpub\wwwroot\testData\CategoryData.vb:198 testData.WebForm1.CategoryGrid_UpdateCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\testData\WebForm1.aspx.vb:115 System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs e) System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) +507 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26 System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +106 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26 System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121 System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +115 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138 System.Web.UI.Page.ProcessRequestMain() +1277 Any Clues?
    Monday, March 1, 2004 4:46 PM

All replies

  • User-2125802522 posted
    Do you maybe have paging turned on with max per page set to 10?
    Monday, March 1, 2004 5:19 PM