Datagrid not paging

G

Guest

Hi Guys,
I have a datagrid wit editing and updating.
But after adding Paging IT WON'T PAGE!!
It compiles well but when i click on the paging link it doesn't go to the
next link..
When i remove AllowCutomPaging it gives error:-
"AllowCustomPaging must be true and VirtualItemCount must be set for a
DataGrid with ID MenuGrid when AllowPaging is set to true and the selected
datasource does not implement ICollection"

My code is below for reference THANKS!

---------------------------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
MenuGrid.VirtualItemCount = 200

' Databind the data grid on the first request only
' (on postback, bind only in editing, paging and sorting commands)

BindDataGrid()

End If

End Sub
Sub BindDataGrid()

Dim DBConnection As SqlConnection
Dim DBCommand As SqlCommand
Dim DBReader As SqlDataReader
Dim SQLString As String

DBConnection = New
SqlConnection("server=(local);database=Northwind;integrated security=true;")
DBConnection.Open()
'SQLString = "SELECT * FROM Products1 ORDER BY ItemNumber"

SQLString = "SELECT * FROM treetable ORDER BY FileCategoryID"

DBCommand = New SqlCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
MenuGrid.DataSource = DBReader
MenuGrid.DataBind()
DBReader.Close()
DBConnection.Close()

End Sub

Sub EditRecord(ByVal Src As Object, ByVal Args As
DataGridCommandEventArgs)
MenuGrid.EditItemIndex = Args.Item.ItemIndex
BindDataGrid()
End Sub

Sub UpdateRecord(ByVal Src As Object, ByVal Args As
DataGridCommandEventArgs)
Dim DBConnection As SqlConnection
Dim DBCommand As SqlCommand
Dim DBReader As SqlDataReader
Dim SQLString As String


' Dim ItemNumber = CType(Args.Item.Cells(0).Controls(0), TextBox).Text
' Dim ItemSupplier = CType(Args.Item.Cells(1).Controls(0),
TextBox).Text
' Dim ItemType = CType(Args.Item.Cells(2).Controls(0), TextBox).Text
' Dim ItemName = CType(Args.Item.Cells(3).Controls(0), TextBox).Text
'Dim ItemPrice = CType(Args.Item.Cells(4).Controls(0), TextBox).Text
'Dim ItemQuantity = CType(Args.Item.Cells(5).Controls(0),
TextBox).Text

Dim FileCategoryID = CType(Args.Item.Cells(0).Controls(0),
TextBox).Text
Dim ParentID = CType(Args.Item.Cells(1).Controls(0), TextBox).Text
Dim FileCategory = CType(Args.Item.Cells(2).Controls(0), TextBox).Text
Dim NavigateUrl = CType(Args.Item.Cells(3).Controls(0), TextBox).Text
Dim Target = CType(Args.Item.Cells(4).Controls(0), TextBox).Text




'SQLString = "UPDATE treetable SET " & _
'"ParentID = '" & ParentID & "', " & _
'"FileCategory = '" & FileCategory & "', " & _
'"NavigateUrl = '" & NavigateUrl & "', " & _
'"Target = '" & Target & "' WHERE FileCategoryID ='" &
FileCategoryID & "'"


SQLString = "UPDATE treetable SET " & _
"ParentID = '" & ParentID & "', " & _
"FileCategory = '" & Replace(FileCategory, "'", "''") & "', " & _
"NavigateUrl = '" & Replace(NavigateUrl, "'", "''") & "', " & _
"Target = '" & Target & "' " & _
"WHERE FileCategoryID ='" & FileCategoryID & "'"



'SQLString = "UPDATE Products1 SET " & _
' "ItemType = '" & ItemType & "', " & _
' "ItemSupplier = '" & Replace(ItemSupplier, "'", "''") &
"', " & _
' "ItemName = '" & Replace(ItemName, "'", "''") & "', " & _
' "ItemPrice = " & ItemPrice & ", " & _
' "ItemQuantity = " & ItemQuantity & " " & _
' "WHERE ItemNumber = '" & ItemNumber & "'"


DBConnection = New
SqlConnection("server=(local);database=Northwind;integrated security=true;")
DBConnection.Open()
DBCommand = New SqlCommand(SQLString, DBConnection)
DBCommand.ExecuteNonQuery()
DBConnection.Close()

MenuGrid.EditItemIndex = -1
BindDataGrid()

End Sub


Sub CancelRecord(ByVal Src As Object, ByVal Args As
DataGridCommandEventArgs)
MenuGrid.EditItemIndex = -1
BindDataGrid()
End Sub
Sub MenuGrid_Page(ByVal Sender As Object, ByVal E As
DataGridPageChangedEventArgs)
MenuGrid.CurrentPageIndex = E.NewPageIndex
BindDataGrid()
End Sub
End Class
-----------------------------------------------------
<asp:DataGrid id="MenuGrid" runat="server"
OnEditCommand="EditRecord"
OnUpdateCommand="UpdateRecord"
OnCancelCommand="CancelRecord"
AutoGenerateColumns="False"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#ffffcc"
CssClass="P"
OnPageIndexChanged="MenuGrid_Page"
PageSize="2"
AllowPaging="True"
AllowCustomPaging="true">
 
L

Lars Netzel

Well, just adding Paging doesn't do the trick fo ryou.

You also need to add the function that will set the page Index

I suggest you take a look at the Event called PageIndexChanged on the
DataGrid

/Lars
 
G

Guest

Hi Lars,
I have a Dataset in the same way with paging and its working fine..
Can u refer an example to me..
thanks
 
G

Guest

Hi Lars,
I have a Dataset in the same way with paging and its working fine..
Can u refer an example to me..
thanks
 
G

Guest

Hi Lars,
I have a Dataset in the same way with paging and its working fine..
Can u refer an example to me..
thanks
 
G

Guest

Hi Lars,
I have a Dataset in the same way with paging and its working fine..
Can u refer an example to me..
thanks
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top