repeater操作

protected void rpRole_ItemDataBound(object sender, RepeaterItemEventArgs e)

{

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)

    {

        DataRowView drv = e.Item.DataItem as DataRowView;

        string roleid = drv["Id"].ToString();

        CheckBox chb = e.Item.FindControl("chbId") as CheckBox;

 

        if (ht.ContainsValue(roleid))

        {

            chb.Checked = true;

        }

 

    }

}

 

 

 

--关于Repeater中嵌套Repeater写法,注意此时html生成二级Repeater的id是多个

protected void rpFn1_ItemDataBound(object sender, RepeaterItemEventArgs e)

{

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)

    {

        DataRowView drv = e.Item.DataItem as DataRowView;

        int functionId = Convert.ToInt32( drv["Id"].ToString());

 

        Repeater rp2 = (Repeater)e.Item.FindControl("rpFn2"); --如果不这样做,就报"当前上下文中不存在名称rpFn2"

 

        DataSet ds2 = new DataSet();

        ds2 = bllF.GetList(-1, "ParentId=" + functionId, "SortBy desc");

        rp2.DataSource = ds2;

        rp2.DataBind();

 

    }

}

 

 

 

datarow[] 绑定可以到datalist等控件

 

 

 刚开始以为不可以绑定到datalist gatagrid repeater等控件 原来是不会写

DataRow[] dr=dt.Select();

   DataGrid1.DataSource=dr;

   DataGrid1.DataBind();

页面得写为

<asp:Label text='<%# DataBinder.eval_r(Container.DataItem,"[\"huifuName\"]")%>' Runat=server></asp:Label>

不能写为<asp:Label text='<%# DataBinder.eval_r(Container.DataItem,"huifuName")%>' Runat=server></asp:Label>

也不能写为<%# ((DataRowView)Container.DataItem["huifuName"]%>

当然一般我们使用选择都是在dataview上操作的 然后将dataview绑定到。。

 

rpFn1_ItemDataBound事件中不能写DataRowView drv = e.Item.DataItem as DataRowView;

要写成:DataRow drv = e.Item.DataItem as DataRow;

 

 

posted @ 2013-10-18 13:11  华子的幸福生活  阅读(242)  评论(0编辑  收藏  举报