473,394 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Datagrid not paging

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
5 1689
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RelaxoRy | last post by:
sqlConnection1.Open(); myReader = sqlCommand1.ExecuteReader(); DataGrid1.DataSource = myReader; DataGrid1.DataBind(); myReader.Close(); sqlConnection1.Close(); The Datagrid populates fine. ...
3
by: Joseph D. DeJohn | last post by:
I am trying to get pagination working on a datagrid. Can anyone point me to a resource for help on this? I'm not sure if custom paging is the best option or not.
2
by: enak | last post by:
I can not get my datagrid to page. I have a datagrid that I can sort 2 of the columns. This works great. I added paging and when I display the dg it shows 5 pages. (I am showing page numbers at...
2
by: RJN | last post by:
Hi Sorry for posting again. I have a datagrid which is put inside a div tag to make it scrollable. I need to page the datagrid. The page numbers appear at the bottom of the datagrid and has...
6
by: Shawn | last post by:
Hi. I already have a datagrid where I'm using paging. I have a stored procedure that fills a temp table with 200-500 rows and then sends back 10 records at the time. When I go to page 2 the SP...
5
by: quanga | last post by:
Hi- I have a datagrid that in some cases can be several thousand rows in length. What I'd like it to do is have the data pushed to the browser after every, say, 100 rows or so. Kind of a...
2
by: Axel Dahmen | last post by:
Hi, I'm using a DataGrid control to show a table's content with paging. For navigation through the pages I'm using the DataGrid's intrinsic navigation section. My problem: The DataGrid...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
0
by: Pat | last post by:
I have 3 Datagrid nested. Master Details Child The master has paging (And i'm using the paging inbuilt in the Datagrid) in the Master DataGrid you select a linkbutton(using commandname) and it...
3
by: Pat | last post by:
I have a 2 nested Datagrid. When i select a row in the Master Datagrid i populate the Child databrid using myDataGrid.SelectedIndex value as the filter and setting the DataKeyField. I enabled...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.