Hi Here is my sub<BR>It works fine when the datagrid has at least one record, but when the datagrid is empty it doesn&#039;t work. Can you help?<BR><BR>Sub AddNew_Click(Sender As Object, E As EventArgs)<BR><BR> &#039; add a new row to the end of the data, and set editing mode &#039;on&#039;<BR><BR> CheckIsEditing("")<BR><BR> If Not isEditing = True Then<BR><BR> &#039; set the flag so we know to do an insert at Update time<BR> AddingNew = True<BR><BR> &#039; add new row to the end of the dataset after binding<BR><BR> &#039; first get the data<BR> Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("c onnectionString"))<BR> &#039;Dim myCommand As New SqlDataAdapter(SelectCommand, myConnection)<BR><BR> Dim ds As New DataSet()<BR> &#039;myCommand.Fill(ds)<BR><BR> &#039; add a new blank row to the end of the data<BR> Dim rowValues As Object() = {"0", "0", "0"}<BR> ds.Tables(0).Rows.Add(rowValues)<BR><BR> &#039; figure out the EditItemIndex, last record on last page<BR> Dim recordCount As Integer = ds.Tables(0).Rows.Count<BR><BR> If recordCount &#062; 1 Then<BR><BR> recordCount -= 1<BR> &#039; DataGrid1.CurrentPageIndex = recordCount DataGrid1.PageSize<BR> DataGrid1.EditItemIndex = recordCount Mod DataGrid1.PageSize<BR><BR> End If<BR><BR> &#039; databind<BR> DataGrid1.DataSource = ds<BR> DataGrid1.DataBind()<BR><BR> End If<BR><BR><BR> End Sub<BR>