zoukankan      html  css  js  c++  java
  • Net4.0数据绑定控件(GridView ListView…)中的ClientIDRowSuffix属性

    在AspNet4中的数据绑定控件(GridView ListView…)中新增了一个ClientIDRowSuffix属性,ClientIDRowSuffix属性可以影响数据绑定控件内部控件的ID,ClientIDRowSuffix控件的值可以设置为数据绑定控件的数据源的任何一列。值得注意的是ClientIDRowSuffix属性是和ClientIDMode属性配合使用的。ClientIDMode有四种属性值,这个在Net4.0---对HTML净化的处理一文中有提到,下面介绍如何在数据绑定控件中使用ClientIDRowSuffix:

    1 在页面中放一个GridView控件,在控件添加一个模板列,模板列中添加一个Lable控件,ID设置为lblId,代码如下:

     
    代码
    <asp:GridView ID="GridView1" runat="server"
    ClientIDRowSuffix
    ="UserId" ClientIDMode="Predictable" >
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:Label ID="lblId" runat="server"></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
     
     
    2 进入后台代码视图,添加一个User类做数据源用,在PageLoad事件中绑定GridView,代码如下:
    代码
    public partial class WebForm1 : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    List
    <User> list = new List<User>
    {
    new User{UserId=10,UserName="oec2003"},
    new User{UserId=20,UserName="oec2004"}
    };
    if (!Page.IsPostBack)
    {
    this.GridView1.DataSource = list;
    this.GridView1.DataBind();
    }
    }
    }
    public class User
    {
    public int UserId { get; set; }
    public string UserName { get; set; }
    }
    3 设置GridView的属性ClientIDMode为不同值,运行程序查看源码,观察Lable控件的ID,如下图:

    AutoID

    2010-07-30_112500

    Inherit

    2010-07-30_112644

    Predictable

    2010-07-30_112747

    Static

    2010-07-30_112954

    总结

    1 根据上图看以看出当ClientIDMode值为Predictable和Inherit时,ClientIDRowSuffix的设置才起了作用,将ClientIDRowSuffix设置的UserId字段的值拼接到了Lable控件的ID属性后。

    2 在网上的一些资料表明ClientIDRowSuffix属性要和ClientIDMode属性一起使用,并且ClientIDMode属性的值要设置成Predictable,但我将GridView中的ClientIDMode属性去掉后运行,看到的源码和设置ClientIDMode为Predictable得到的源码一致。也就是说只设置GrieView的ClientIDRowSuffix就可以得到想要的结果。

    3 ClientIDRowSuffix属性还可以设置对应多个字段,如ClientIDRowSuffix="UserId,UserName",这样得到的控件的ID是多个字段值的拼接。

    4 在AspNet4的数据绑定控件中,只有GridView和ListView有ClientIDRowSuffix属性。

    出处: http://oec2003.cnblogs.com/

  • 相关阅读:
    如何开始DDD(续)
    如何开始DDD
    ThinkNet终于见面了
    [Umbraco] umbraco中如何分页
    ETL 工具下载全集 包括 Informatica Datastage Cognos( 持续更新)
    js时间对比-转化为几天前,几小时前,几分钟前
    原生JS实现返回顶部和滚动锚点
    JSONP原理及简单实现 可做简单插件使用
    CSS3 transition效果 360度旋转 旋转放大 放大 移动
    js获取url的常用方法
  • 原文地址:https://www.cnblogs.com/LCX/p/1913209.html
Copyright © 2011-2022 走看看