ObjectDataSource.MaximumRowsParameterName Tulajdonság
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Lekéri vagy beállítja az üzleti objektum adatlekérési metódusparaméterének nevét, amely az adatforrás lapozási támogatásához beolvasandó rekordok számát jelzi.
public:
property System::String ^ MaximumRowsParameterName { System::String ^ get(); void set(System::String ^ value); };
public string MaximumRowsParameterName { get; set; }
member this.MaximumRowsParameterName : string with get, set
Public Property MaximumRowsParameterName As String
Tulajdonság értéke
Annak a paraméternek a SelectMethod neve, amely a lekérendő rekordok számát jelzi. Az alapértelmezett érték a "maximumRows".
Példák
Az alábbi három példa egy weblapot, egy kód mögötti laposztályt és egy adatelérési osztályt mutat be, amely lehetővé teszi, hogy a felhasználó kiválaszthatja, hogy hány rekord jelenjen meg a lapon.
A weblap egy vezérlőelemet ObjectDataSource tartalmaz, amelynek EnablePaging a tulajdonsága a következőre truevan állítva. A SelectCountMethod tulajdonság egy metódus nevére van beállítva, amely a lekérdezésben szereplő rekordok teljes számát adja vissza. A MaximumRowsParameterName tulajdonság és a StartRowIndexParameterName tulajdonság a Select metódusban használt paraméterek nevére van állítva. A lap egy vezérlőt DropDownList is tartalmaz.
<html xmlns="http://www.w3.org/1999/xhtml">
<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>
<html xmlns="http://www.w3.org/1999/xhtml">
<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>
A második példa egy kezelőt mutat be a ListControl.SelectedIndexChangedDropDownList vezérlő eseményéhez. A kezelőben lévő kód a PageSize tulajdonságot a felhasználó kiválasztására állítja be.
protected void rowsToDisplay_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.PageSize = int.Parse(rowsToDisplay.SelectedValue);
}
Protected Sub rowsToDisplay_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rowsToDisplay.SelectedIndexChanged
GridView1.PageSize = Integer.Parse(rowsToDisplay.SelectedValue)
End Sub
A harmadik példa azt az adatelérési osztályt mutatja be, amely adatokat kér le az Ügyfelek táblából. Tartalmaz egy metódust GetSubsetOfEmployees, amely a SelectMethod vezérlőelem tulajdonságához ObjectDataSource van hozzárendelve. A példa tartalmaz egy metódust GetEmployeeCountis, amely a SelectCountMethod vezérlőelem tulajdonságához ObjectDataSource van rendelve. Az osztály a LINQ használatával kérdezi le az Ügyfelek táblát. A példához linq to SQL osztály szükséges, amely a Northwind adatbázist és az Ügyfelek táblát jelöli. További információ: Hogyan is: LINQ létrehozása SQL-osztályokhoz webes Project.
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;
}
}
}
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
Megjegyzések
A MaximumRowsParameterName tulajdonság az adatforrások lapozásának támogatására szolgál. További információ arról, hogy a vezérlőelem hogyan támogatja a ObjectDataSource lapozást: EnablePaging.
A MaximumRowsParameterName tulajdonság delegálja a MaximumRowsParameterName vezérlőelemhez társított objektum tulajdonságát ObjectDataSourceViewObjectDataSource .