Gets or sets the name of the data retrieval method parameter that is used to indicate the value of the identifier of the first record to retrieve for data source paging support.
Namespace:
System.Web.UI.WebControls
Assembly:
System.Web (in System.Web.dll)
Visual Basic (Declaration)
Public Property StartRowIndexParameterName As String
Dim instance As ObjectDataSource
Dim value As String
value = instance.StartRowIndexParameterName
instance.StartRowIndexParameterName = value
public string StartRowIndexParameterName { get; set; }
public:
property String^ StartRowIndexParameterName {
String^ get ();
void set (String^ value);
}
public function get StartRowIndexParameterName () : String
public function set StartRowIndexParameterName (value : String)
<asp:ObjectDataSource StartRowIndexParameterName="String" />
Property Value
Type:
System..::.StringThe name of the business object method parameter used to indicate the first record to retrieve. The parameter must return an integer value. The default is "startRowIndex".
The StartRowIndexParameterName property is used to support data source paging. For information about how paging is supported by the ObjectDataSource control, see EnablePaging.
The StartRowIndexParameterName property delegates to the StartRowIndexParameterName property of the ObjectDataSourceView object that is associated with the ObjectDataSource control.
The following three examples show a Web page, a code-behind page class, and a data-access class that enable the user to pick how many records are displayed in the page.
The Web page contains an ObjectDataSource control whose EnablePaging property is set to true. The SelectCountMethod property is set to the name of a method that returns the total number of records in the query. The MaximumRowsParameterName property and the StartRowIndexParameterName property are set to the names of the parameters that are used in the Select method. The page also contains a DropDownList control.
<html >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
How many rows to display on this page:<br />
<asp:DropDownList
AutoPostBack="true"
ID="rowsToDisplay"
runat="server"
onselectedindexchanged="rowsToDisplay_SelectedIndexChanged">
<asp:ListItem Value="5"></asp:ListItem>
<asp:ListItem Value="10" Selected="True"></asp:ListItem>
<asp:ListItem Value="20"></asp:ListItem>
</asp:DropDownList>
<asp:ObjectDataSource
SelectCountMethod="GetEmployeeCount"
EnablePaging="true"
TypeName="CustomerLogic"
SelectMethod="GetSubsetOfEmployees"
MaximumRowsParameterName="maxRows"
StartRowIndexParameterName="startRows"
ID="ObjectDataSource1"
runat="server">
</asp:ObjectDataSource>
<asp:GridView
DataSourceID="ObjectDataSource1"
AllowPaging="true"
ID="GridView1"
runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
<html >
<head runat="server">
<title>ObjectDataSource Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
How many rows to display on this page:<br />
<asp:DropDownList
AutoPostBack="true"
ID="rowsToDisplay"
runat="server"
onselectedindexchanged="rowsToDisplay_SelectedIndexChanged">
<asp:ListItem Value="5"></asp:ListItem>
<asp:ListItem Value="10" Selected="True"></asp:ListItem>
<asp:ListItem Value="20"></asp:ListItem>
</asp:DropDownList>
<asp:ObjectDataSource
SelectCountMethod="GetEmployeeCount"
EnablePaging="true"
TypeName="CustomerLogic"
SelectMethod="GetSubsetOfEmployees"
MaximumRowsParameterName="maxRows"
StartRowIndexParameterName="startRows"
ID="ObjectDataSource1"
runat="server">
</asp:ObjectDataSource>
<asp:GridView
DataSourceID="ObjectDataSource1"
AllowPaging="true"
ID="GridView1"
runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
The second example shows a handler for the ListControl..::.SelectedIndexChanged event of the DropDownList control. The code in the handler sets the PageSize property to the user's selection.
Protected Sub rowsToDisplay_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rowsToDisplay.SelectedIndexChanged
GridView1.PageSize = Integer.Parse(rowsToDisplay.SelectedValue)
End Sub
protected void rowsToDisplay_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.PageSize = int.Parse(rowsToDisplay.SelectedValue);
}
The third example shows the data access class that retrieves data from the Customers table. It includes a method named GetSubsetOfEmployees, which is assigned to the SelectMethod property of the ObjectDataSource control. The example also includes a method named GetEmployeeCount, which is assigned to the SelectCountMethod property of the ObjectDataSource control. The class uses LINQ to query the Customers table. The example requires a LINQ to SQL class that represents the Northwind database and Customers table. For more information, see How to: Create LINQ to SQL Classes in a Web Application.
Public Class CustomerLogic
Public Function GetSubsetOfEmployees(ByVal startRows As Integer, ByVal maxRows As Integer) As List(Of Customer)
Dim ndc As New NorthwindDataContext()
Dim customerQuery = _
From c In ndc.Customers _
Select c
Return customerQuery.Skip(startRows).Take(maxRows).ToList()
End Function
Public Function GetEmployeeCount() As Integer
Dim cachedCount = HttpRuntime.Cache("TotalEmployeeCount")
If cachedCount IsNot Nothing Then
Return Integer.Parse(cachedCount.ToString())
Else
Dim ndc As New NorthwindDataContext()
Dim totalNumberQuery = _
From c In ndc.Customers _
Select c
Dim employeeCount = totalNumberQuery.Count()
HttpRuntime.Cache.Add("TotalEmployeeCount", employeeCount, Nothing, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration, CacheItemPriority.Normal, Nothing)
Return employeeCount
End If
End Function
End Class
public class CustomerLogic
{
public List<Customer> GetSubsetOfEmployees(int startRows, int maxRows)
{
NorthwindDataContext ndc = new NorthwindDataContext();
var customerQuery =
from c in ndc.Customers
select c;
return customerQuery.Skip(startRows).Take(maxRows).ToList<Customer>();
}
public int GetEmployeeCount()
{
object cachedCount = HttpRuntime.Cache["TotalEmployeeCount"];
if (cachedCount != null)
{
return int.Parse(cachedCount.ToString());
}
else
{
NorthwindDataContext ndc = new NorthwindDataContext();
var totalNumberQuery =
from c in ndc.Customers
select c;
int employeeCount = totalNumberQuery.Count();
HttpRuntime.Cache.Add("TotalEmployeeCount", employeeCount, null, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
return employeeCount;
}
}
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0
Reference
Other Resources