Note that there are some explanatory texts on larger screens.

plurals
  1. POIndexOutOfRangeException. There is no row at position 0
    primarykey
    data
    text
    <p>Trying to update data in a GridView and received an exception error. Originally, I had <strong>GridView1.EditIndex = -1</strong>, then I read up that the index number should not be a negative so I changed it to <strong>=1</strong> but still it didn't work.</p> <pre><code>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim dt As New DataTable("historyList") dt.Columns.Add("TicketID", GetType(Integer)) dt.Columns.Add("DateCreated", GetType(DateTime)) dt.Columns.Add("FullName", GetType(String)) dt.Columns.Add("TicketType", GetType(String)) dt.Columns.Add("Subject", GetType(String)) dt.Columns.Add("Message", GetType(String)) dt.Columns.Add("Status", GetType(String)) For i = 0 To 6 Dim tableRow = dt.NewRow() tableRow("TicketID") = i tableRow("DateCreated") = Now() tableRow("FullName") = i.ToString() tableRow("TicketType") = i.ToString() tableRow("Subject") = i.ToString() tableRow("Message") = i.ToString() tableRow("Status") = i.ToString() Next Session("dt") = dt BindData() End Sub Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) GridView1.EditIndex = e.NewEditIndex BindData() End Sub Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs) GridView1.EditIndex = 1 BindData() End Sub Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Dim dt = CType(Session("dt"), DataTable) 'if your current DataSource be in Session Dim row As GridViewRow = GridView1.Rows(e.RowIndex) dt.Rows(row.DataItemIndex)("TicketID") = (CType(row.Cells(0).Controls(0), TextBox)).Text dt.Rows(row.DataItemIndex)("DateCreated") = (CType(row.Cells(1).Controls(0), TextBox)).Text dt.Rows(row.DataItemIndex)("FullName") = (CType(row.Cells(2).Controls(0), TextBox)).Text dt.Rows(row.DataItemIndex)("TicketType") = (CType(row.Cells(3).Controls(0), TextBox)).Text dt.Rows(row.DataItemIndex)("Subject") = (CType(row.Cells(4).Controls(0), TextBox)).Text dt.Rows(row.DataItemIndex)("Message") = (CType(row.Cells(5).Controls(0), TextBox)).Text dt.Rows(row.DataItemIndex)("Status") = (CType(row.Cells(6).Controls(0), TextBox)).Text Session("dt") = dt GridView1.EditIndex = 1 BindData() End Sub Private Sub BindData() GridView1.DataBind() End Sub </code></pre> <p>So, here's my aspx codes:</p> <pre><code> &lt;asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="TicketID" DataSourceID="historySqlDataSource" ForeColor="#333333" GridLines="None" Width="828px" OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowUpdating="GridView1_RowUpdating"&gt; &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt; &lt;Columns&gt; &lt;asp:CommandField ShowEditButton="True" /&gt; &lt;asp:BoundField DataField="TicketID" HeaderText="TicketID" InsertVisible="False" ReadOnly="True" SortExpression="TicketID" /&gt; &lt;asp:BoundField DataField="DateCreated" HeaderText="DateCreated" SortExpression="DateCreated" /&gt; &lt;asp:BoundField DataField="FullName" HeaderText="FullName" SortExpression="FullName" /&gt; &lt;asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" /&gt; &lt;asp:BoundField DataField="TicketType" HeaderText="TicketType" SortExpression="TicketType" /&gt; &lt;asp:BoundField DataField="Subject" HeaderText="Subject" SortExpression="Subject" /&gt; &lt;asp:BoundField DataField="Message" HeaderText="Message" SortExpression="Message" /&gt; &lt;asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" /&gt; &lt;/Columns&gt; &lt;EditRowStyle BackColor="#999999" /&gt; &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt; &lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt; &lt;PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /&gt; &lt;RowStyle BackColor="#F7F6F3" ForeColor="#333333" /&gt; &lt;SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /&gt; &lt;SortedAscendingCellStyle BackColor="#E9E7E2" /&gt; &lt;SortedAscendingHeaderStyle BackColor="#506C8C" /&gt; &lt;SortedDescendingCellStyle BackColor="#FFFDF8" /&gt; &lt;SortedDescendingHeaderStyle BackColor="#6F8DAE" /&gt; &lt;/asp:GridView&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload