This is a migrated thread and some comments may be shown as answers.

RadGrid Custom Paging using ObjectDataSource

1 Answer 250 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marietta
Top achievements
Rank 1
Marietta asked on 11 Mar 2009, 07:17 PM

Hi,

I am using Custom paging with ObjectDataSource control and I am getting this error:

 

 'ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'GetGLCount' that has parameters: startRowIndex, maximumRows. '

 

Can somebody help to identify where is the problem?

Thanks!

This my code:

[ASPX page]

 

 

 

<%

@ Page Language="vb" AutoEventWireup="false" CodeBehind="UsingObjectDataSource.aspx.vb" Inherits="TelerikTestingMillionRecords.UsingObjectDataSource" %>

 

<%

@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

 

<!

 

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<

 

html xmlns="http://www.w3.org/1999/xhtml" >

 

<

 

head runat="server">

 

 

<title>Untitled Page</title>

 

</

 

head>

 

<

 

body>

 

 

<form id="form1" runat="server">

 

 

<div>

 

 

<asp:ScriptManager ID="ScriptManager1" runat="server">

 

 

</asp:ScriptManager>

 

 

 

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">

 

 

<AjaxSettings>

 

 

<telerik:AjaxSetting AjaxControlID="RadGrid1">

 

 

<UpdatedControls>

 

 

<telerik:AjaxUpdatedControl ControlID="RadGrid1" />

 

 

</UpdatedControls>

 

 

</telerik:AjaxSetting>

 

 

</AjaxSettings>

 

 

</telerik:RadAjaxManager>

 

 

 

<telerik:RadGrid ID="RadGrid1" runat="server" Width="95%" Skin="Hay"

 

 

DataSourceID="ObjectDataSource1"

 

 

ShowGroupPanel="True"

 

 

ShowStatusBar="True"

 

 

AllowPaging="True"

 

 

AllowSorting="True" GridLines="None">

 

 

<ClientSettings AllowDragToGroup="true" />

 

 

<HeaderContextMenu Skin="Hay">

 

 

<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>

 

 

</HeaderContextMenu>

 

 

<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>

 

 

<MasterTableView OverrideDataSourceControlSorting="true" />

 

 

<FilterMenu Skin="Hay">

 

 

<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>

 

 

</FilterMenu>

 

 

</telerik:RadGrid>

 

 

 

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"

 

 

EnablePaging="True"

 

 

SelectCountMethod="GetGLCount"

 

 

SelectMethod="GetGLSubSet"

 

 

OldValuesParameterFormatString="original_{0}"

 

 

TypeName="TelerikTestingMillionRecords.SQLDataManager">

 

 

<SelectParameters>

 

 

<asp:Parameter DefaultValue="1" Name="startRowIndex" Type="Int32" />

 

 

<asp:Parameter DefaultValue="15" Name="maximumRows" Type="Int32" />

 

 

</SelectParameters>

 

 

</asp:ObjectDataSource>

 

 

</div>

 

 

</form>

 

</

 

body>

 

</

 

html>

 

 

 

[Code Behind]

 

Imports

 

System.Data.SqlClient

 

Imports

 

Telerik.Web.UI

 

Imports

 

TelerikTestingMillionRecords.SQLDataManager

 

Partial

 

Public Class UsingObjectDataSource

 

 

Inherits System.Web.UI.Page

 

 

 

 

 

Private Sub ObjectDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) Handles ObjectDataSource1.Selecting

 

e.InputParameters(

"startRowIndex") = 1

 

e.InputParameters(

"maximumRows") = 15

 

 

End Sub

 

 

 

[DAL]

 

Imports

 

System.Data.SqlClient

 

Public

 

Class SQLDataManager

 

 

Public Sub New()

 

 

End Sub

 

 

Shared Function GetGLSubSet(ByVal startRowIndex As Integer, ByVal maximumRows As Integer) As Data.DataSet

 

 

' Data adapter to retrieve data from SQL Server based on the page size of the grid.

 

 

' The Select statement uses the maximumRows and startRowIndex parameters provided

 

 

' by WebGrid to query for data between the start row index for the page up to the page size.

 

 

Dim ConnString As String = ConfigurationManager.ConnectionStrings("PCRSQL2005ConnectionString").ConnectionString

 

 

'Create a connection to the SQL Server.

 

 

Dim conn As SqlConnection = New SqlConnection(ConnString)

 

conn.Open()

 

Dim MyDataAdapter As SqlDataAdapter

 

 

'Create a DataAdapter, and then provide the name of the stored procedure.

 

MyDataAdapter =

New SqlDataAdapter("GetPCRGLIFP100Subset", conn)

 

 

'Set the command type as StoredProcedure.

 

MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

 

'Create and add a parameter to Parameters collection for the stored procedure.

 

MyDataAdapter.SelectCommand.Parameters.Add(

New SqlParameter("@startRowIndex", SqlDbType.Int))

 

MyDataAdapter.SelectCommand.Parameters.Add(

New SqlParameter("@maximumRows", SqlDbType.Int))

 

 

'Assign the search value to the parameter.

 

MyDataAdapter.SelectCommand.Parameters(

"@startRowIndex").Value = startRowIndex

 

MyDataAdapter.SelectCommand.Parameters(

"@maximumRows").Value = maximumRows

 

 

Dim ds As New DataSet

 

MyDataAdapter.Fill(ds)

MyDataAdapter.Dispose()

conn.Close()

 

Return ds

 

 

End Function

 

 

Public Shared Function GetGLCount() As Integer

 

 

' Data adapter to retrieve data from SQL Server based on the page size of the grid.

 

 

' The Select statement uses the maximumRows and startRowIndex parameters provided

 

 

' by WebGrid to query for data between the start row index for the page up to the page size.

 

 

Dim ConnString As String = ConfigurationManager.ConnectionStrings("PCRSQL2005ConnectionString").ConnectionString

 

 

'Create a connection to the SQL Server.

 

 

Dim conn As SqlConnection = New SqlConnection(ConnString)

 

conn.Open()

 

Dim MyDataAdapter As SqlDataAdapter

 

 

'Create a DataAdapter, and then provide the name of the stored procedure.

 

MyDataAdapter =

New SqlDataAdapter("GetPCRGLIFP100RowCount", conn)

 

 

'Set the command type as StoredProcedure.

 

MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

 

'Create and add a parameter to Parameters collection for the stored procedure.

 

MyDataAdapter.SelectCommand.Parameters.Add(

New SqlParameter("@MaximumRows", SqlDbType.Int))

 

 

'Create and add an output parameter to Parameters collection.

 

 

'Set the direction for the parameter. This parameter returns the Rows returned.

 

MyDataAdapter.SelectCommand.Parameters(

"@MaximumRows").Direction = ParameterDirection.Output

 

 

Dim ds As New DataSet

 

MyDataAdapter.Fill(ds)

 

'Get the number of rows returned, and then assign it to the Label control.

 

 

'lblRowCount.Text = DS.Tables(0).Rows.Count().ToString() & " Rows Found!"

 

GetGLCount = MyDataAdapter.SelectCommand.Parameters(0).Value

MyDataAdapter.Dispose()

conn.Close()

 

End Function

 

End

 

Class

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Mar 2009, 06:05 AM
Hi Marietta,

For Paging you need to set the parameters.

 Identifying Paging Parameters:

You can specify additional parameters for a Select method that identify a page of data to be returned. The ObjectDataSource control supports two properties that identify paging parameters:

    * The StartRowIndexParameterName property identifies the name of a parameter in the business object's select method that is used to specify the starting row of the page of data.
    * The MaximumRowsParameterName property identifies the name of a parameter in a in the business object's select method that is used to specify the number of rows in the page of data.

Both parameters identified by the StartRowIndexParameterName and MaximumRowsParameterName properties are of type Int32.

The following code example shows an ObjectDataSource control configured to pass sort and page parameters to the Select method of the specified business object:

CS:
<asp:ObjectDataSource  
  ID="EmployeesObjectDataSource"  
  runat="server"  
  TypeName="Samples.AspNet.Controls.NorthwindEmployee"  
  SortParameterName="SortColumns" 
  EnablePaging="true" 
  StartRowIndexParameterName="StartRecord" 
  MaximumRowsParameterName="MaxRecords"  
  SelectMethod="GetAllEmployees" > 
</asp:ObjectDataSource>  

Refer the following link for more details.
Using Parameters with the ObjectDataSource Control





Thanks
Shinu


Tags
Grid
Asked by
Marietta
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or