These days to learn how to bind the data, and then the bound data for paging processing, has been difficult to understand before, but hands-on practice only to find that it is not difficult. The following is a brief introduction to the use of the DataGrid control. First, select the DataGrid control in the menu bar
If not added, right-click the tab, and then add the DataGrid control to the Toolbox:
As shown in the following illustration: Note to select. NET Framework Components
Ii. implementing data binding and pagination processing
As shown in the following illustration:
The advantage of the DataGrid control is that it automatically encapsulates a feature about paging, without requiring us to write code, click Settings directly
Here's a description of our code: For convenience, we bind data to a grid and encapsulate it as a method, the name of which is our control's name:
<span style= "FONT-SIZE:18PX;" >private void BindToDataGrid1 ()
{
//binds data to the grid
SqlConnection con = Dbc.createcon ();
SqlDataAdapter SDA = new SqlDataAdapter ();
Sda. SelectCommand = new SqlCommand ("SELECT * from News", con);
DataSet ds = new DataSet ();
Sda. Fill (ds, "emp");
This. DataGrid1.DataSource = ds. tables["EMP"];
This. Datagrid1.databind ();
} </span>
For when we click on the next page, there will be different data, we use a pageindexchanged
<span style= "FONT-SIZE:18PX;" > protected void datagrid1_pageindexchanged (object source, DataGridPageChangedEventArgs e)
{
// The current number is how much this
. Datagrid1.currentpageindex = E.newpageindex;
This. BindToDataGrid1 ();
} </span>
Every time we click on the next page, we reload the page.
<span style= "FONT-SIZE:18PX;" > protected void Page_Load (object sender, EventArgs e)
{
if (! Page. IsPostBack)
{this
. BindToDataGrid1 ();
}
}
</span>
Okay, it's almost over. Using the DataGrid control for data binding and paging, let's look at the effect:
Summary:
The advantage of paging in the DataGrid control is that it is easy to operate and can be visualized, which makes it easy for us to use, but it is also what we call false paging, and it is easy to run slow when processing large amounts of data.