• 数据绑定控件的笔记


    1. Repeater 用于轻量级的数据的绑定  

    元素:

    头部元素:HeaderTemplate 头部

    绑定数据的项:ItemTemplate 

    AlternatingItemTemplate 交替项显示数据的

    <%# Eval("BookName")%>  给每一个项绑定数据元 

      Eval (只能用于显示)  Bind (显示与输出)

    CommandName="update" CommandArgument='<%# Eval("BookID") %>' 

    设置这两个值能设置获取获取对象的ID值 列如:

      <asp:LinkButton ID="lbDelete" OnClientClick="return confirm('确ā?定¨要癮删?除y??')" CommandName="delete" CommandArgument='<%# Eval("BookID") %>' runat="server">删除</asp:LinkButton>

    -------------------------------------------------------------------

    SeparatorTemplate 包含在每项之间呈现的元素,定刑的示例可能是使用一条水平线(html的 hr 元素)

     <SeparatorTemplate>

           <tr>

               <td colspan="5">

                 <hr />

               </td>

            </tr>

     </SeparatorTemplate>

    footerTemplate  Repeater 的底部显示的数据、、、、

     

     

     PagedDataSource  数据的分页

    DataSource—设置数据源

    CurrentPageIndex—设置或获得当前页

    PageSize—设置或获得每页记录数

    Allowpaging—设置控件是否实现自动分页

     

    列如;

     DataTable table = DBUtil.GetTable(sql);

     //分?页?数簓据Y源′的?使?用?

     PagedDataSource pds = new PagedDataSource();

     pds.DataSource = table.DefaultView;//给DataSource 对象设置数据源

    pds.CurrentPageIndex = Pager - 1;//设置挡墙页的索引

    pds.AllowPaging = true;//启动分页

    pds.PageSize = 5;//每页多少汗数据

    this.rptBookInfo.DataSource = pds;//绑定数据

    this.rptBookInfo.DataBind();

    --------------------------------------------------------------------

    DataList的使用

    事件:

    EditControl 编辑事件  DeleteControl 删除

    UpdateControl   CancelControl 取消事件

    元素:

     

    ItemTemplate 绑定数据的项 

    EditItemTemplate 编辑项 当点击编辑时会执行EditItemTemplate 里面的代码,

     

     CommandName="edit" CommandArgument='<%# Eval("BookID") %>' 

    点击后编辑,必须设置以上的两个属性

    //将点击编辑的项,设置为编辑模式的状态

    this.dlBookInfos.EditItemIndex = e.Item.ItemIndex;

    DataListBind();//给Datalist绑定数据

    删除项 将CommanName=“delete”

    OnClientClick="return confirm('确定要癮删除?')" CommandName="delete" CommandArgument='<%# Eval("BookID") %>'

     

    取消 将CommanName设为 "cancel" 

    this.dlBookInfos.EditItemIndex = -1;//将要编辑的项设为-1;

    DataListBind();//给Datalist绑定数据

     

    /获取绑定的CommandArgument值(一般都是主键值)

     int bookId = Convert.ToInt32(e.CommandArgument);

    //获取文本的值

    String bookName=((TextBox)e.Item.FindControl("txtBookName")).Text;

    e.Item.FindControl("txtBookName")//寻找 一个这样的控件,它的类型为system.Web.UI. Control 必须把它转为TextBox才能获取它的值。

     -----------------------------------------------------------------------------------

    GridView 控件的使用

    DataKeyNames 设置对象的IID 用在于添删改

    AutoGenerateColumns  设置是否自动添加行

    FageSize 设置分页时,每页的行数

    PageIndexChanging 索引值改变时发生 里面写分页的代码

    RowDataBound  在対行进行绑定后触发 用于光棒效果

    如://判D断?当獭?前°操ù作痢?的?行D是?否?为a数簓据Y行D

            if (e.Row.RowType == DataControlRowType.DataRow)

            {

                e.Row.Attributes.Add("onmouseover", "currentColor=this.style.backgroundColor;this.style.backgroundColor='yellow'");

                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentColor");

            }

    ---------------------------------------------

    可以用来存放全局变量   分页的当前页

        public int Num
        {
            get { return Convert.ToInt32(ViewState["num"]);}
            set { ViewState["num"] = value; }
        }

     

     

     

     

     

     

     

  • 相关阅读:
    UIWebView 视频播放获取开始播放和结束播放通知
    显示图像数据的高级接口 UIImage
    如何跳到系统设置里的WiFi界面
    Objective-C 去掉NSString 前后中空格
    iOS 属性修饰符的区别
    iOS 线程锁同步机制
    XCode 6 以后使用编程处理一些图片效果
    iOS 精益编程
    iOS7以后UITextView 技巧
    2016年12月英语六级阅读真题及答案 第3套
  • 原文地址:https://www.cnblogs.com/cl1006/p/3987570.html
Copyright © 2020-2023  润新知