By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,934 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,934 IT Pros & Developers. It's quick & easy.

Datagrid not paging

P: n/a
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;i ntegrated 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;i ntegrated 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">
Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

"Patrick.O.Ige" <Pa*********@discussions.microsoft.com> skrev i meddelandet
news:6B**********************************@microsof t.com...
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;i ntegrated 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;i ntegrated 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">

Nov 18 '05 #2

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

"Lars Netzel" wrote:
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

"Patrick.O.Ige" <Pa*********@discussions.microsoft.com> skrev i meddelandet
news:6B**********************************@microsof t.com...
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;i ntegrated

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;i ntegrated

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">


Nov 18 '05 #3

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

"Lars Netzel" wrote:
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

"Patrick.O.Ige" <Pa*********@discussions.microsoft.com> skrev i meddelandet
news:6B**********************************@microsof t.com...
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;i ntegrated

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;i ntegrated

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">


Nov 18 '05 #4

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

"Lars Netzel" wrote:
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

"Patrick.O.Ige" <Pa*********@discussions.microsoft.com> skrev i meddelandet
news:6B**********************************@microsof t.com...
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;i ntegrated

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;i ntegrated

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">


Nov 18 '05 #5

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

"Lars Netzel" wrote:
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

"Patrick.O.Ige" <Pa*********@discussions.microsoft.com> skrev i meddelandet
news:6B**********************************@microsof t.com...
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;i ntegrated

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;i ntegrated

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">


Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.