共用方式為


DataPagerFieldCollection.Add(DataPagerField) 方法

定義

將指定 DataPagerField 物件附加到集合中。

public:
 void Add(System::Web::UI::WebControls::DataPagerField ^ field);
public void Add (System.Web.UI.WebControls.DataPagerField field);
member this.Add : System.Web.UI.WebControls.DataPagerField -> unit
Public Sub Add (field As DataPagerField)

參數

field
DataPagerField

要附加到集合中的物件。

範例

下列範例示範如何使用 Add 方法將 物件新增 NextPreviousPagerFieldDataPager 控件。

void Page_Load(Object sender, EventArgs e)
{
  
  // Dynamically generated field pagers need to be created only 
  // the first time the page is loaded.
  
  if (!IsPostBack)
  {
    // Create a NextPreviousPagerField object to display
    // the buttons to navigate.
    NextPreviousPagerField pagerField = new NextPreviousPagerField();
    pagerField.ShowFirstPageButton = true;
    pagerField.ShowLastPageButton = true;
    pagerField.ButtonType = ButtonType.Button;

    // Add the pager field to the Fields collection of the
    // DataPager control.
    ContactsDataPager.Fields.Add(pagerField);
  }

  ContactsListView.DataBind();

}
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
  
  ' Dynamically generated field pagers need to be created only 
  ' the first time the page is loaded.

  If Not IsPostBack Then
    ' Create a NextPreviousPagerField object to display
    ' the buttons to navigate.
    Dim pagerField As New NextPreviousPagerField()
    pagerField.ShowFirstPageButton = True
    pagerField.ShowLastPageButton = True
    pagerField.ButtonType = ButtonType.Button

    ' Add the pager field to the Fields collection of the
    ' DataPager control.
    ContactsDataPager.Fields.Add(pagerField)
  End If
      
  ContactsListView.DataBind()

End Sub

備註

物件 DataPagerField 會加入至集合結尾。

適用於

另請參閱