DataPagerCommandEventArgs.NewStartRowIndex Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the index of the first record to display on a page of data.
public:
property int NewStartRowIndex { int get(); void set(int value); };
public int NewStartRowIndex { get; set; }
member this.NewStartRowIndex : int with get, set
Public Property NewStartRowIndex As Integer
Property Value
The index of the first record that will be displayed on a page of data.
Examples
The following example shows how to use the NewStartRowIndex property to set the index of the first record to display in a ListView control. The record to display is based on the page number that is specified by the user. This code example is part of a larger example provided for the DataPagerCommandEventArgs class.
protected void TemplatePagerField_OnPagerCommand(object sender, DataPagerCommandEventArgs e)
{
// Get the new page number
TextBox PageNumberTextBox = (TextBox)e.Item.FindControl("PageNumberTextBox");
int newPageNumber = -1;
try
{
newPageNumber = Convert.ToInt32(PageNumberTextBox.Text.Trim());
}
catch (FormatException)
{
Message.Text = "Invalid page number.";
return;
}
catch (OverflowException)
{
Message.Text = "Invalid page number.";
return;
}
int newIndex = (newPageNumber - 1) * e.Item.Pager.PageSize;
//Verify if the new index is valid
if (newIndex >= 0 && newIndex <= e.TotalRowCount)
{
//Set the new start index and maximum rows
e.NewStartRowIndex = newIndex;
e.NewMaximumRows = e.Item.Pager.MaximumRows;
}
else
Message.Text = "Invalid page number.";
}
Protected Sub TemplatePagerField_OnPagerCommand(ByVal sender As Object, _
ByVal e As DataPagerCommandEventArgs)
' Get the new page number
Dim PageNumberTextBox As TextBox = _
CType(e.Item.FindControl("PageNumberTextBox"), TextBox)
Dim newPageNumber As Integer = -1
Try
newPageNumber = Convert.ToInt32(PageNumberTextBox.Text.Trim())
Catch fex As FormatException
Message.Text = "Invalid page number."
Return
Catch oex As OverflowException
Message.Text = "Invalid page number."
Return
End Try
Dim newIndex As Integer = _
(newPageNumber - 1) * e.Item.Pager.PageSize
'Verify if the new index is valid
If newIndex >= 0 AndAlso newIndex <= e.TotalRowCount Then
'Set the new start index and maximum rows
e.NewStartRowIndex = newIndex
e.NewMaximumRows = e.Item.Pager.MaximumRows
Else
Message.Text = "Invalid page number."
End If
End Sub
Remarks
You usually set this property to change the page number that is currently being displayed.
When you set a value for the NewStartRowIndex property, you must also set the NewMaximumRows property.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기