Gridview / Form View Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using a Gridview to display a phone directory, with paging on. I have a
link button that a user clicks to add a new record, which reloads the page,
sets the visble property to false on the gridview and shows the form view in
insert mode. Upon saving, the process is reversed. All is well and dandy,
however I want to jump to the page that has the newly entered record, with
the record highlighted. Does anyone know how to do this?
I believe I would need a dataview to find the inserted record and to get
it's row index, but I do not know how to get the dataview from a
SQLDATASOURCE.
 
To all. I figured this one out. I have included my source code for anyone who
may need it:

Protected Sub frmView_ItemInserted(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles
frmView.ItemInserted
Dim dv As DataView =
CType(sql.Select(DataSourceSelectArguments.Empty), DataView)
Dim empLoc As String = CType(Session("EmpLoc"), String)
Dim employee As String = CType(Session("Employee"), String)
Dim key(1) As Object
Dim selectKey As Integer = -1
Dim selectPage As Integer = 1

key(0) = empLoc
key(1) = employee

dv.Sort = "EmpLoc, Employee"
selectKey = dv.Find(key)

selectPage = selectKey / gvPhone.PageSize
If selectKey Mod gvPhone.PageSize = 0 Then selectPage -= 1


gvPhone.PageIndex = selectPage
selectKey -= selectPage * gvPhone.PageSize
gvPhone.SelectedIndex = selectKey

Response.Write("selectKey: " + selectKey.ToString + "<br />")
Response.Write("selectPage: " + selectPage.ToString)
End Sub

Protected Sub frmView_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.FormViewInsertEventArgs) Handles
frmView.ItemInserting
Session("EmpLoc") = e.Values.Item(2).ToString
Session("Employee") = e.Values.Item(1).ToString
End Sub

Tahnks...
 
John said:
To all. I figured this one out. I have included my source code for anyone who
may need it:

Protected Sub frmView_ItemInserted(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles
frmView.ItemInserted
Dim dv As DataView =
CType(sql.Select(DataSourceSelectArguments.Empty), DataView)
Dim empLoc As String = CType(Session("EmpLoc"), String)
Dim employee As String = CType(Session("Employee"), String)
Dim key(1) As Object
Dim selectKey As Integer = -1
Dim selectPage As Integer = 1

key(0) = empLoc
key(1) = employee

dv.Sort = "EmpLoc, Employee"
selectKey = dv.Find(key)

selectPage = selectKey / gvPhone.PageSize
If selectKey Mod gvPhone.PageSize = 0 Then selectPage -= 1


gvPhone.PageIndex = selectPage
selectKey -= selectPage * gvPhone.PageSize
gvPhone.SelectedIndex = selectKey

Response.Write("selectKey: " + selectKey.ToString + "<br />")
Response.Write("selectPage: " + selectPage.ToString)
End Sub

Protected Sub frmView_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.FormViewInsertEventArgs) Handles
frmView.ItemInserting
Session("EmpLoc") = e.Values.Item(2).ToString
Session("Employee") = e.Values.Item(1).ToString
End Sub

Tahnks...

but, John, you only gave us 40 minutes ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top