Paging Database Results in ASP.NET (Prt1)(转载:http:

转载 2008年05月01日 03:23:00
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src=""> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src=""> </script>
For More" target=_blank>information on" target=_blank>ASP." target=_blank>NET
This article exam" target=_blank>ines how to create a databound listbox us" target=_blank>ing" target=_blank>ASP." target=_blank>NET. For more" target=_blank>information on" target=_blank>ASP." target=_blank>NET be sure to check out the articles" target=_blank>in the" target=_blank>ASP." target=_blank>NET Article" target=_blank>index. The code" target=_blank>in this article is based on the Beta 2 version of" target=_blank>ASP." target=_blank>NET. To learn more about the free" target=_blank>ASP." target=_blank>NET Beta 2, be sure to check out this FAQ." target=_blank>introduction
One of the most common tasks developers are faced with when work" target=_blank>ing with data-driven Web sites is the need to page data. Most data is only worthwhile if it can easily be digested by a human, so a data-driven Web site needs to present data" target=_blank>in an easy-to-read format." target=_blank>in situations where a large chunk of data is presented to the user, it helps to break up this" target=_blank>information" target=_blank>into multiple pages." target=_blank>Pag" target=_blank>ing data is noth" target=_blank>ing new, just about every search eng" target=_blank>ine and eCommerce site employs the technique. If you wonder over to Google and search on" target=_blank>ASP you'll get back over five million" target=_blank>Results! Imag" target=_blank>ine if Google attempted to show all five million matches on one Web page!" target=_blank>instead, to make the" target=_blank>information digestable by human eyes (i.e., yours), Google presents the" target=_blank>Results" target=_blank>in chunks of ten records per page." target=_blank>in this article we will look at how to implement" target=_blank>Pag" target=_blank>ing" target=_blank>Database" target=_blank>Results us" target=_blank>ing" target=_blank>ASP." target=_blank>NET. It is surpris" target=_blank>ingly simple, requir" target=_blank>ing just a few l" target=_blank>ines of code!" target=_blank>Database" target=_blank>Pag" target=_blank>ing" target=_blank>in Classic" target=_blank>ASP" target=_blank>Pag" target=_blank>ing" target=_blank>in classic" target=_blank>ASP was possible via a number of means. One of the most common ways was to use the" target=_blank>Pag" target=_blank>ing properties provided" target=_blank>in the ADO Recordset object. Even when us" target=_blank>ing these properties, developers still were required to write a lot of code to handle" target=_blank>Pag" target=_blank>ing correctly. (For more" target=_blank>information on" target=_blank>Pag" target=_blank>ing" target=_blank>Results us" target=_blank>ing this method" target=_blank>in classic" target=_blank>ASP, be sure to read this article.) Other methods were available as well, such as us" target=_blank>ing a stored procedure as well client-side script techniques. However, all of these methods required much code and, usually, a hapless" target=_blank>intermix" target=_blank>ing of HTML and script code." target=_blank>Database" target=_blank>Pag" target=_blank>ing" target=_blank>in" target=_blank>ASP." target=_blank>NET
Fortunately," target=_blank>Pag" target=_blank>ing" target=_blank>Database" target=_blank>Results" target=_blank>in" target=_blank>ASP." target=_blank>NET is much cleaner and much easier with" target=_blank>ASP." target=_blank>NET than with classic" target=_blank>ASP." target=_blank>in this article we'll look at us" target=_blank>ing a DataGrid Web control to implement" target=_blank>Pag" target=_blank>ing. The beautiful th" target=_blank>ing about the DataGrid Web control is that it handles" target=_blank>Pag" target=_blank>ing itself, mean" target=_blank>ing the amount of actual code we have to write is very little" target=_blank>indeed. First th" target=_blank>ings first, though, let's look at an" target=_blank>ASP." target=_blank>NET Web page that b" target=_blank>inds a DataSet to a DataGrid Web control. (We'll then exam" target=_blank>ine how to page these" target=_blank>Results.)

Below you can see what the HTML portion of our" target=_blank>ASP." target=_blank>NET page needs to look like. At absolute m" target=_blank>inimum, it just needs to conta" target=_blank>in a DataGrid control. I have set some properties" target=_blank>in the DataGrid control to enhance its appearance; these ehancements, however, are optional:

    <" target=_blank>ASP:datagrid id="dgPopularFAQs" runat="server" BorderWidth="0"
       CellPadd" target=_blank>ing="2" Width="100%"
       Alternat" target=_blank>ingItemStyle-BackColor="#dddddd">
    </" target=_blank>ASP:datagrid>

Next, we need to write code that will query our" target=_blank>Database, populat" target=_blank>ing a DataSet with the" target=_blank>Results of some SQL query. Once we have this populated DataSet, we'll b" target=_blank>ind the DataSet to the DataGrid Web control, dgPopularFAQs. The code for connect" target=_blank>ing to a Microsoft SQL Server 7.0 or greater" target=_blank>Database can be seen below. (If you are us" target=_blank>ing a different" target=_blank>Database, change all" target=_blank>instances of Sql below to OleDb (i.e., change Dim myDA as New SqlDataAdapter() to Dim myDA as New OleDbDataAdapter()).)

<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<script language="vb" runat="server">
  Sub Page_Load(sender as Object, e as EventArgs)
    B" target=_blank>indData()
  End Sub
  Sub B" target=_blank>indData()
    '1. Create a connection
    Dim myConnection as New SqlConnection(<i>ConnectionStr" target=_blank>ing</i>)

    '2. Create the command object, pass" target=_blank>ing" target=_blank>in the SQL str" target=_blank>ing
    Const strSQL as Str" target=_blank>ing = "SELECT FAQID, Description, DateEntered, ViewCount " & _
                             "FROM tblFAQ ORDER BY FAQID"
    Dim myCommand as New SqlCommand(strSQL, myConnection)

    '3. Create the DataAdapter
    Dim myDA as New SqlDataAdapter()
    myDA.SelectCommand = myCommand

    '4. Populate the DataSet
    Dim myDS as New DataSet()

    '5. Set the datagrid's datasource to the dataset and datab" target=_blank>ind
    dgPopularFAQs.DataSource = myDS
    dgPopularFAQs.DataB" target=_blank>ind()    
  End Sub

... HTML section omitted for brevity ...

[View a live demo!]

Note that the ConnectionStr" target=_blank>ing property should be a valid connection str" target=_blank>ing for the SQL" target=_blank>Database. For example: server=IPAddress;uid=userName;pwd=password;" target=_blank>Database=" target=_blank>DatabaseName. (Of course, the OleDb connection str" target=_blank>ing is slightly different; refer to the documentation for more" target=_blank>information.) Note that we are perform" target=_blank>ing five steps here:

Connect to the" target=_blank>Database.

Create the command object based upon the SQL query we wish to run and the connection object we wish to run it on.

Create the DataAdapter. This object is needed to fill a DataSet with the" target=_blank>Database" target=_blank>Results.

Populate the DataSet object with the" target=_blank>Results from the" target=_blank>Database query.

B" target=_blank>ind the DataSet to the DataGrid Web control.
Note that with" target=_blank>ASP." target=_blank>NET it's that easy to display" target=_blank>Database" target=_blank>information" target=_blank>in a visually appeal" target=_blank>ing format. Do take a moment to view the live demo and note how nice the DataGrid control appears. Also note that with this technique there is no shameless mix" target=_blank>ing of HTML and script code, as would be the case" target=_blank>in a classic" target=_blank>ASP page." target=_blank>in Part 2 we'll look at how to improve the data display of the DataGrid Web control by hav" target=_blank>ing the data paged. As you'll see" target=_blank>in Part 2, this only requires a few l" target=_blank>ines of code!

11AIXW35011944.jpg" target=_blank>ing/wangzhanyouhua/" title="seo,搜索引擎优化">seover="w" target=_blank>indow.status='正文--" target=_blank>Pag" target=_blank>ing" target=_blank>Database" target=_blank>Results" target=_blank>in" target=_blank>ASP." target=_blank>NET (" target=_blank>Prt1)(" target=_blank>转载:[登级:初级]';return true">
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src=""> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src=""> </script>

Paging Database Results in ASP.NET (Prt2)(转载:http:

  • zgqtxwd
  • zgqtxwd
  • 2008年05月01日 02:53
  • 136

ZK Paging组件实现动态分页,描述很通俗易懂

zul页面:     Xml代码     zul 页面:  xml version="1.0" encoding="utf-8"?>  init class="org.zkos...
  • gaozhlzh
  • gaozhlzh
  • 2011年10月26日 14:26
  • 3847 mvc分页的实现 mvcpaging

首先需要准备的东西 本文查询的方式为linq to entity mvcpaging.dll分页控件 可以从
  • HuangYanManCao
  • HuangYanManCao
  • 2013年03月12日 10:33
  • 1456


346.What is the impact of the results of the output of the following command? RMAN> report unrecove...
  • rlhua
  • rlhua
  • 2013年10月07日 10:03
  • 7056


FROM: 首先,将下载的工具箱文件解压,将文件夹复制到MATLAB安装目录下to...
  • fenxian2011
  • fenxian2011
  • 2014年02月28日 19:25
  • 1296

读书笔记之-unix操作系统设计---Demand Paging

今天讲讲Demand Paging,以前的UNIX操作系统在PDP-11上使用的是Swapping,而不是Demand Paging,这是因为Demang Paging需要硬件的支持(...
  • collide
  • collide
  • 2004年09月21日 10:18
  • 3592

[Pthread] Linux中的内存管理(一)--Paging

  • Javadino
  • Javadino
  • 2008年09月06日 14:48
  • 3465


Memory: Information about the usage of virtual and real memory. Virtual pages are considered active ...
  • zhaoyangjian724
  • zhaoyangjian724
  • 2017年02月10日 07:55
  • 264

apple的各种联系方式,原文链接 -应用在提交后(处于“审核中”),应用和应用内购的状态 -状态更新通知——与开发者遭拒和影响审核时间相关的信息 -应用遭拒通知咨询-快速审核请求 -------...
  • u011421203
  • u011421203
  • 2014年09月25日 10:01
  • 1424

LTE paging注释

  • zhangingong
  • zhangingong
  • 2017年08月30日 11:37
  • 1271
您举报文章:Paging Database Results in ASP.NET (Prt1)(转载:http: