打印

[asp.net教程] 即刻完成你的asp.net程序(1)

即刻完成你的asp.net程序(1)

asp.net的出现,使网络程序员们设计程序的时候完全找到了“设计程序”的感觉,当然,更多的,他们感觉到了asp.net的得心应手。但是,没有想偷懒就没有进步,如果你仅仅依靠asp.net自己的强大功能而不想其他手段,那你很快就会发现别人设计程序比你会快很多而且轻轻松松。现在,我们来学习几招偷懒的手段,让别人跟在你后面敬佩吧。
  使用过asp的朋友一定都记得,asp的很多功能需要一些第三方的组件实现,比如文件上传功能的实现就往往使用aspcnup组件实现。使用这些组件,不但可以扩展asp程序的功能,而且,大大提高程序开发速度。我们这里介绍的偷懒手段,也就是介绍几款与我们平时设计密切相关的组件。
  一、超级数据表格:superdatagrid
  asp.net自带的datgrid功能强大,定制也很方便,但是,因为它不是专门为数据库应用设计的。所以,在连接数据库的时候,我们不得不首先连接数据库,然后绑定数据。而superdatagrid是专门为数据库设计的,所以,那些繁琐的连接数据库我们也就没有必要去写了。需要
  superdatagrid将datagrid的一些属性简单化,使用这个控件,我们可以方便的实现数据库数据的显示、排序、修改数据,这些功能的实现,只要简单几行代码就可以。我们现在来看它的使用。
  一)显示数据表
  以下代码演示怎样使用superdatagrid来简单的显示数据表中的所有数据:
  <%@ register tagprefix="super" namespace="superexpert.data"
  assembly="superexpert.superdatagrid" %>
   
  <super:superdatagrid
  connectionstring="server=localhost;uid=demo;pwd=secret;database=pubs"
  tablename="titles"
  runat="server" />
  具体效果请看:
  http://www.superexpertcontrols.com/superdatagrid/samples/sample1.aspx
  现在,我们来简单分析以上代码。第一行使调用superdatagrid控件,我们在以后的举例中都将使用到。第二行,和标准的datagrid使用差不多,我们看看superdatagrid的一些属性:
  connectionstring:因为是连接数据库,当然少不了数据库连接语句。这个参数就是连接数据的语句;
  tablename:要显示具体的表,我们就在这里定义。
  看到这里,我们已经感觉到了“简单”,但是,在实际的应用中,像这种直接显示一个表的情况是很少的。所以,我们需要其他更多的功能。最直接的,我们需要select语句的返回结果。
  <%@ register tagprefix="super" namespace="superexpert.data"
  assembly="superexpert.superdatagrid" %>
   
  <super:superdatagrid
  connectionstring="server=localhost;uid=sa;pwd=secret;database=northwind"
  commandtext="select productname, categoryname
  from products, categories where products.categoryid=categories.categoryid"
  runat="server" />
  具体效果请看:
  http://www.superexpertcontrols.com/superdatagrid/samples/sample2.aspx
  以上代码返回select语句的结果。在这里,我们见到一个新的属性:

  commandtext:和command一样,就是select语句;
  二)数据排序
  在datagrid中,数据排序虽然简单,但是代码还是不少。我们现在来看superdatagrid中怎样给数据排序:
  <%@ register tagprefix="super" namespace="superexpert.data"
  assembly="superexpert.superdatagrid" %>
   
  <form runat="server">
  <super:superdatagrid
  connectionstring="server=localhost;uid=sa;pwd=secret;database=pubs"
  tablename="titles"
  enablesorting="true"
  runat="server" />
  </form>
  具体效果请看:
  http://www.superexpertcontrols.com/superdatagrid/samples/sample3.aspx
  仔细看以上代码,其实就是设置了一个enablesortinga属性为真。也就是打开排序功能。需要仔细注意的一点,要将superdatagrid包括在form中。

TOP

返回顶部
AYBlue

Processed in 0.052198 second(s), 7 queries.

当前时区 GMT+8, 现在时间是 2009-1-10 11:05 京ICP备06054220号

清除 Cookies - 联系我们 - 163K.com - Archiver - WAP