I have a datagrid where I have a template column. In the template column I have added a button to insert a new row. When I click on the button, textboxes with preliminary values appear. Currently I have them at the beginning of the datagrid by using
trailersDG.EditItemIndex = 0
But I would like to add them to the end of the datagrid. How can I get the EditItemIndex of the last row thus allowing me to use paging? Here is what I have so far.
Public Sub AddNewRow(sender As Object, e As EventArgs)
Dim queryString As String = "INSERT INTO trlrTypes(equipmentCode,equipmentType) VALUES('nt','New Type')"
Dim dbCommand As IDbCommand = New OleDbCommand(queryString, dbConnection)
dbConnection.Open
dbCommand.ExecuteNonQuery
Dim nNewItemIndex As Integer = trailersDG.Items.Count
If nNewItemIndex >= trailersDG.PageSize Then
trailersDG.CurrentPageIndex += 1
nNewItemIndex = 0
End If
trailersDG.EditItemindex = nNewItemIndex
dbConnection.close
UpdateView()
End Sub
Private Sub UpdateView()
trailersDG.EditItemIndex = 0
BindTrailers()
End Sub
Thanks for the reply, I had fixed it myself already. All I needed to do was remove the call to UpdateView and instead make a call to BindTrailers(). Now when a new row is created in the datagrid, there are two textboxes for editing. Now I just have to figure out how to add some clientside javascript to set the focus onto the first textbox.
You could do something like this to set the focus.
function SetFocus(){
var dg = document.getElementById("DataGrid1");
var arrElems = dg.getElementsByTagName("input");
for(i=0;i<arrElems.length;i++){
if(arrElems[i].type.toLowerCase()=="text"){
arrElems[i].focus();
break;
}
}
}