MicroHelper.Net

雷锋说.对待朋友要MicroHelper,对待敌人要害尔扑
随笔 - 74, 评论 - 431, 引用 - 7

导航

关于

邮件系统不稳定,使用songdming at 263 dot net吧
PageRank

FastCounter by bCentral

 

标签

每月存档

最新留言

  • re: 代码组织
    <a href="http://www.vgoldseller.com/runescape-c-599.html">runescape money</a> ...
    by cxb000(匿名) on 2008/3/26 10:32:11
  • 回复: 看PPMM
    <a target="_new" href="http://www.bestgoldlion.com">http://www.bestgoldlio...
    by runescape gold(匿名) on 2007/12/18 5:13:00
  • 回复: IoC初阶
    <a target="_new" href="http://www.bestgoldlion.com">http://www.bestgoldlio...
    by runescape gold(匿名) on 2007/12/18 5:12:00
  • 回复: 数据分页 (最后更新2003/11/18)
    <a target="_new" href="http://www.sky361.com">http://www.sky361.com</a&...
    by wow power leveling(匿名) on 2007/12/18 5:06:00
  • 回复: iBATIS.Net
    <a target="_new" href="http://www.rsgold-rsgold.com">http://www.rsgold-rsg...
    by runescape money(匿名) on 2007/12/18 5:04:00
  • 回复: 防范Sql注入式攻击
    <a target="_new" href="http://www.rsgold-rsgold.com">http://www.rsgold-rsg...
    by runescape money(匿名) on 2007/12/18 5:03:00
  • 回复: TDD——NUnit的原理
    <a target="_new" href="http://www.rsgold-rsgold.com">http://www.rsgold-rsg...
    by runescape money(匿名) on 2007/12/18 5:03:00
  • 回复: 开源的CMS
    <a target="_new" href="http://www.rsgold-rsgold.com">http://www.rsgold-rsg...
    by runescape money(匿名) on 2007/12/18 5:03:00
  • 回复: CCNet 1.0即将发布
    <a target="_new" href="http://www.sky361.com">http://www.sky361.com</a&...
    by runescape gold(匿名) on 2007/12/18 5:00:00
  • 回复: 关于加班
    为什么这年头加班都成了是我们 的义务了?加班不给加班费也就算了,难得早点回去,还要说三道四的,这社会会为什么会发展成这样啊????
    by 小小(匿名) on 2007/12/14 8:18:00
  • 回复: Presentation草稿:面向对象设计的基本原则
    是的,模式要实事求是,应该是解决问题为主 <br>我搜集了原则方面的文章,有空去看看吧 <br><a target="_new" href="...
    by objecttutor(匿名) on 2007/10/31 17:26:00
  • 回复: 开源的CMS
    支持一下
    by qingxingmeng(匿名) on 2007/10/30 18:03:00
  • 回复: .Net的开源项目
    AnyView(网络警)网络监控软件是一款国内目前最专业的企业级的网络监控软件产品。包含局域网上网监控、邮件监控、聊天监控、BT禁止、流量监视、上下行分离流量限制、并发连接数限制、屏幕监视和录象、硬件...
    by 网络监控软件(匿名) on 2007/10/30 12:33:00
  • 回复: .Net的开源项目
    AnyView(网络警)网络监控软件是一款国内目前最专业的企业级的网络监控软件产品。包含局域网上网监控、邮件监控、聊天监控、BT禁止、流量监视、上下行分离流量限制、并发连接数限制、屏幕监视和录象、硬件...
    by 网络监控软件(匿名) on 2007/10/30 12:32:00
  • 回复: 看PPMM
    好看就成 <br>
    by 11(匿名) on 2007/10/27 15:43:00

广告

smartNavigation罪行

1:

相对路径路径丢失

比如:<LINK href="css\ie6.css" type=text/css rel=stylesheet>,当叶面提交过后,相对路径丢失

2:

Script失效

比如:
<INPUT id=Button1 type=button value=Button name=Button1 runat="server">

<SCRIPT language=vbscript id=clientEventHandlersVBS>
<!--
    Sub Button1_onclick
        msgbox "a"
    End Sub
-->
</SCRIPT>

 private void Button1_ServerClick(object sender, System.EventArgs e)
  {
   Response.Write ("Click");
  }

当叶面提交过后,Client端的Script:Button1_onclick失效

posted on 2003-09-28 16:52:00 by microhelper  评论(3) 阅读(2591)

Page Catch

Page Catch

posted on 2003-09-28 11:34:00 by microhelper  评论(0) 阅读(240)

数据排序

Creating a Pageable, Sortable DataGrid By Scott Mitchell

属性

SortExpression:列的排序表达式(不一定与DataField不一定相同)。当AutoGenerateColumns属性为True时,DataGrid每一列的SortExpressionoperty被自动设为绑定到该行的Data Field,如果AutoGenerateColumns为False,需要手工设置。

事件

SortCommand:一般的情况下为Click排序列的Head时触发,参数为DataGridSortCommandEventArgs e,在SortCommand事件里可以将排序后的DataSource重新绑定到DataGrid上。

定制

可以在ItemCreated事件里对排序列的Head进行定制,比如,若e.Item.ItemType=ListItemType.Header,可以在Head后面添加表示排序方向的箭头

string strSortBy  = (string) ViewState["SortExpression"];
string strSortAscending  = (string) ViewState["SortAscdening"];
string strOrder = ("yes" == strSortAscending ? "5" : "6");
Label Lbl_Sorted  = new Label();
Lbl_Sorted.Font.Name = "webdings";
Lbl_Sorted.Font.Size = FontUnit.XSmall;
Lbl_Sorted.Text = " " + strOrder;
e.Item.Cells[i].Controls.Add(Lbl_Sorted);

可以将排序的相关状态存储在ViewState中

注:对分页以及多列排序需要特别注意。

posted on 2003-09-27 15:10:00 by microhelper  评论(1) 阅读(1794)

数据分页 (最后更新2003/11/18)

ASP.NET Data Web Controls: Providing DataGrid Pagination By Scott Mitchell
Paging through Records using a Stored Procedure By Daniel Anderson
Paging In ASP.NET By Andrew Merlino

 


属性

AllowSorting: 是否允许分页
PageSize: 页的大小
CurrentPageIndex: 当前页,CurrentPageIndex应该大于等于0并且小于等于PageCount
PageCount :页数
VirtualItemCount: DataGrid需要根据Record的数目来计算页数,但是Custom Paging模式不需要一次得到所有的Record,所以需要显式为VirtualItemCount赋值

事件

PageIndexChanged: 改变PageIndex时触发。在PageIndexChanged中更新CurrentPageIndex属性并且重新绑定DataSource(一定要重新绑定,如果不重新绑定DataSource的话DataGrid会用ViewState的信息)

定制

DataGridPagerStyle类或者来控制显示
包括BackColor;Font;ForeColor;HorizontalAlign;Mode;NextPageText;PrevPageText;PageButtonCount;Position;Width

如果要自定义导航栏,比如1,2 -->[1],[2]可以在OnItemCreated事件里面实现,DataGrid的页导航栏是TableRow对象,包含一个跨越所有列的TableCell对象,要访问分页按钮,需要遍历TableRow的Controls集合,(分页按钮之间的空格也是控件,遍历时可以跳过)

如果要实现更复杂的导航栏,可以把DataGrid自带的导航栏的Visible属性设置为False,然后加入自己的导航栏,自定义的导航栏是与DataGrid可以是相互独立的。

更复杂的定制可以在OnItemCreated事件里面实现。

Default Paging模式

设置AllowSorting为True,只显示PageSize大小的reocrd
如果DataGrid分页模式用Default Paging, 那么DataSource需要是一个实现ICollection接口的对象,因为DataGrid需要知道DataSouce对象有多少Record(DataSet实现了ICollection接口但是DataReader没有)。
Default Paging模式下,会接受所有的Data,但是只显示其中一部分。

Custom Paging模式

如果DataGrid分页模式用Custom Paging,DataSource不需要实现ICollection,所以可以用DataReader。

获得VirtualItemCount可以用ExecuteScalar,ExecuteScalar执行查询,只返回查询所返回的结果集中第一行的第一列。

要计算某一个Reocrd是DataSource中的第几个reccord,可以在存储过程中借助一个含有递增field(比如:IncreasingID int IDENTITY(1,1))的临时表,但是此法不适用于数据量非常大的情况

对于以递增的整数为主键的table,可以把每页的最小主键的最大主键保存下来,然后结合select top和order by来实现分页(注意order by的顺序,要根据查看前一页还是查看后一页决定用DESC还是用ASC),不过这种方法不适用Mode="NumericPages"

或者用set rowcount xxxx来代替select top,不过不要忘了最后调用set rowcount 0

或者将DataSource的PrimaryKey排序后存入ArrayList中,然后根据PageSize,CurrentPageIndex,NewPageIndex等计算出此页的PrimaryKey范围,用Join和GetRange将该范围内的PrimaryKey组成一个字符串,传入存储过程select ... from ... where ... And PrimaryKeyColumn IN (...)。因为有Index的协助,对PrimaryKey的操作应该非常快。

或者用嵌套的select top语句,比如每页n条记录,要查看第m页, 可以

select top * from (
    select top n * from 
        (select top n*m * from table_name order by primarykey)
     order by primarykey desc
)order by primarykey

说实话,这方法很笨

还有一种比较快的方法是利用Database的游标,例子如下

declare @pagesize int
declare @page int
declare @total int
declare @start int
declare @end int
declare @maxid int
declare @minid int

set @pagesize = 10
set @page = 0  --Page从0开始

select @start = @page * @pagesize + 1
select @end   = @start+ @pagesize - 1

declare pagecursor cursor SCROLL for
select contact_id from table_contact order by contact_id

open pagecursor
set @total = @@CURSOR_ROWS

fetch absolute @start from pagecursor into @minid
if @end > @total
fetch last from pagecursor into @maxid
else
fetch absolute @end from pagecursor into @maxid

close pagecursor
deallocate pagecursor

select contact_id, contact_firstname, contact_lastname
from table_contact
where contact_id between @minid and @maxid
order by contact_id

对不支持分页的控件可以借助于PagedDataSource类。

 

posted on 2003-09-27 14:23:00 by microhelper  评论(4) 阅读(5369)

Powered by: Joycode.MVC引擎 0.5.2.0