个人小结-浅谈数据绑定控件

1:Repeater,DataList,DataGrid,GridView都是用来显示数据的WebControl,它们支持Event Bubble【事件冒泡】,它们中的子控件的事件可以上升到本身的事件,通过一个子例程和事件关联。采用的方法是OnItemCommand.

2:DataList,DataGrid对于子例程更具体,有ItemCommand,UpdateCommand,EditCommand,DeleteCommand,CancelCommand他们通过CommandName来执行触发哪个子例程

比如:DataList

CancelCommand:由子控件CommandName="cancel"触发.
DeleteCommand:CommandName
="delete"
UpdateCommand:CommandName
="update"
EditCommand:CommandName
="edit"
ItemCommand:其他CommandName




注意:
包含在DataList中的Button,HpyperLinkButton,ImageButton可以触发以上事件。
DataList中包含的子例程必须有[u]DataListCommandEventArgs[/u]参数,这个参数表示DataList传递给子历程的信息
   DataListCommandEventArgs
        |-----CommandName:引发事件控件的CommandName
        |-----CommandArgument:引发事件控件的CommandArgument
        |-----CommandSource:引发事件的控件对象
        |-----Item:DataList的一个条目


3:GridView主要是RowCommand,RowEditing,RowUpdating

4:他们都用模板机制。
共有的模板:ItemTemplate,AlternatingTemplate,SeparatorTemplate,HeaderTemplate,FooterTemplate

5:DataList有Repeater的所有模板,又加了2个模板SelectedItemTemplate,EditItemTemplate

6:它们可以通过FindControl查找自己的子控件
FindControl方法用来搜搜一个容器,寻找制定的ID的控件,如果找不到,它返回0

7:DataList,DataGrid,GridView都有DataKeys集合。通过DataKeyField设置。而Repeater没有。

8:对于数据绑定,
>Repeater,DataList通过DataBinder.Eval来实现数据库的数据绑定。
>DataGrid,GridView利用<Columns></Columns>里的绑定列[BoundColumn],超级链接列[HyperLinkColumn],按钮列[ButtonColumn],模板列 [TemplateColumn]实现数据绑定.
>DataGrid不用任何模板就可以显示数据。当然这只能AutoGenerateColumns="true"
9:DataList中用RepeateLayout属性可以用来设置每行显示的格式.它有2个属性值:html+flow.默认为html。每行数据显示在table的单元格里。如果改成flow,每行数据就会显示在<span></span>标签里。

10:绑定控件的常见属性
    <1>BackColor 背景色
    <2>BorderColor:边框的颜色
    <3>BorderStyle:solid,dased,dotted,groove,inset,outset等
    <4>BorderWidth
    <5>CssClass:与条目相关联的级联样式单类
    <6>Font系列:Font-Bold,Font-Names,Font-size,Font-Names,Font-UnderLine
    <7>ForeColor
    <8>Height
    <9>HorizontalAlign
    <10>VerrticalAlign
    <11>Width
    <12>Wrap:是否单行回绕
    <13> CellSpacing,CellPadding

DataList,DataGrid还可以通过ItemStyle-的前缀设置ItemTemplate的属性
注意:模板和样式是独立的。没有依赖关系。
10:DataList除了有ReatLayout独特的属性外,还有RepeatColumns,RepeatDirection2个属性来创建多列。
DataGrid却有BackImageURL设置DataGrid的背景图像
11:关于分页
>Repeater控件是最忠实于模版原样,它可以利用System.Web.UI.WebControls.PagedDataSource实现分页
>DataList是DataGrid,Repeater的融合品,它的功能也特别强大,但可惜没有内置的分页功能。可以利用DataSet,SqlDataAdapter组合就可以实现分页。
sdr.Fill(dataset,StartIndex,PageSize,"score")

>DataGrid功能比Repeater,DataList都强大。它有内置的分页和排序.只要设置DataGrid的相关属性就可以实现分页。比如:AllowPaging=true PageSize=10  PageIndexChanged


 

  protected void dgURL_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
        
{
            
this.dgURL.CurrentPageIndex = e.NewPageIndex;
            MmyeeAd.BLL.ADManage.WebSite bll 
= new MmyeeAd.BLL.ADManage.WebSite();
            DataSet ds 
= bll.GetList(" 1=1 ");
            
this.dgURL.DataSource = ds.Tables[0].DefaultView;
            
this.dgURL.DataBind();
        }



GridView事件详解

posted @ 2007-06-10 14:33  roboth  阅读(498)  评论(1编辑  收藏  举报