Hi,
I tried the code and I get the following error:
Specified argument was out of the range of valid values. Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index
Source Error:
Line 123:
Line 124: For LoopCount = 0 To pager.Controls.Count - 1
Line 125: Dim o As Control = CType(pager.Controls(LoopCount), Control)
Line 126:
Line 127: newPager.Controls.AddAt(0, o)
Source File: d:\site\BackOffice\paging.aspx.
vb Line: 125
The code in
vb:
Sub fillTable()
sid = "43fdgr6"
U_ID = txtSearch.Text
cmd = oConn.CreateCommand
cmd.CommandText = "SELECT * from USERS WHERE U_ID like '%'+@U_ID+'%' ORDER BY U_ID DESC"
cmd.Parameters.Add("@U_ID", U_ID)
cmd.Parameters.Add("@sid", sid)
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable("ads")
da.Fill(dt)
DataGrid1.DataSource = dt
DataGrid1.DataBind()
End Sub
Sub doPaging(ByVal s As Object, ByVal e As DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
fillTable()
End Sub
Private Sub btnMsg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMsg.Click
Response.Redirect("edituser.aspx?sid=" & sid)
End Sub
Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles DataGrid1.ItemCommand
If e.Item.ItemIndex >= 0 Then
Dim userCell As TableCell = e.Item.Cells(0)
Dim user As String = userCell.Text
If e.CommandSource.commandname = "Update" Then
Response.Redirect("editUser.aspx?u_id=" & user & "&sid=" & sid)
End If
If e.CommandSource.commandname = "ShowAll" Then
Response.Redirect("Usermsg.aspx?u_id=" & user & "&sid=" & sid)
End If
End If
End Sub
Public Sub ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
Dim elemType As ListItemType = e.Item.ItemType
Dim LoopCount As Integer
Dim pager As TableCell = CType(e.Item.Controls(0), TableCell)
Dim newPager As New TableCell
For LoopCount = 0 To pager.Controls.Count - 1
Dim o As Control = CType(pager.Controls(LoopCount), Control)
newPager.Controls.AddAt(0, o)
Next LoopCount
e.Item.Controls.RemoveAt(0)
e.Item.Controls.AddAt(0, newPager)
End Sub 'ItemCreated
End Class