how to show 20 rows on datagrid each time?
i show data on gridview like this:
SQL = "SELECT * FROM MEN ";
dsView = new DataSet();
adp = new SqlDataAdapter(SQL, Conn);
adp.Fill(dsView, "MEN");
adp.Dispose();
GridView1.DataSource = dsView.Tables["MEN"];
GridView1.DataBind();
but i see along list...
how to show Every time only 10 rows ?
i work on 开发者_运维问答asp.net and C#
Yes, use a paged datagrid. Its a better practice.
EDIT : <asp:DataGrid ID="DataGrid1" AllowPaging="True" />
After allowing paging to datagrid, you'l need to do something like this..
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
}
See an an example for datagrids, here.
You can add LIMIT 10
to only show 10 rows.
LIMIT 30, 10
will show 10 rows, starting at row 30.
I did a blog post on Custom Paging and Sorting for the Telerik RadGrid. The concepts are still valid for an ASP GridView.
http://dotnetblogger.com/post/2010/03/07/RadGrid-with-Custom-Paging-Sorting-Filtering.aspx
Basically you want to add pagination to your grid and you probably don't want to return everything "*" from your database.
Pagination will increase DB performance and site speed dramatically. Trust me.
1) Also you can achieve this by using Stored Procedure, Please see here for more. RowNumber does the magic in SQL Server, I am not sure about Oracle or other DB whether RowNumber exist in that.
CREATE PROCEDURE [dbo].[sp_getzipcodes]
@start int = 0
AS
BEGIN
Set NOCOUNT ON
SELECT TOP 20 * FROM
(
SELECT zip,city,state,latitude,longitude,timezone,dst,
ROW_NUMBER() OVER (ORDER BY zip) AS num
FROM dbo.zipcode
) AS a
WHERE num > @start
END
2)
You can use Pagination, Just need to set following attributes at grid tags,
AllowPaging="True" and PageSize="25".
AllowPaging: setting for Pagination. PageSize : Displaying number of records on the page.
精彩评论