I prototyped what you have and this is what I found
1 - DataItemCount is always zero ??!
2- i set to count will cause an index out of range
Protected Sub Page_init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim CurrentRecord As Int32 = Request.QueryString("user_id")
Dim i As Int32
For i = 0 To FormView1.DataItemCount - 1
Response.Write(i)
If FormView1.DataKey(i).value = CurrentRecord Then
FormView1.PageIndex = cstr(CurrentRecord)
Exit For
End If
Next
End Sub
So I tried this instead and it worked for me.
Partial Class NdxByQryStr
Inherits System.Web.UI.Page
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Dim cr As Integer = Request("id")
Dim i As Integer = 0
Do While DataBinder.Eval(FormView1.DataItem, "CategoryId") <> cr
FormView1.PageIndex = i
FormView1.DataBind()
If DataBinder.Eval(FormView1.DataItem, "CategoryId") = cr Then
Exit Do
End If
i += 1
Loop
End Sub
End Class