zoukankan      html  css  js  c++  java
  • repeat 的两个事件ItemDataBound和ItemCommand

    ItemDataBound主要是用来最后改变一次repeat在客户端加载的数据主要用来设置 ItemCommand主要是利用repeat的按钮控件的CommandName和CommandArgument

    1.ItemCommand实例

             protected void Repeater3_ItemCommand(object source, RepeaterCommandEventArgs e)
            {
                if (e.CommandName == "启用")//CommandName主要使前台代码和后台代码打交道
                {
                    T_UsersTableAdapter adapter = new T_UsersTableAdapter();
                    long id=  Convert.ToInt64(e.CommandArgument);//CommandArgument主要使后台与数据库打交道
                    adapter.AlterjiyongById(id);
                    Repeater3.DataBind();
                }
                else if (e.CommandName == "禁用")
                {
                    T_UsersTableAdapter adapter = new T_UsersTableAdapter();
                    long id = Convert.ToInt64(e.CommandArgument);
                    adapter.AlterqiyongByID(id);
                    Repeater3.DataBind();

                }
                else {
                    throw new Exception("有错");
                }
            }

    2. ItemDataBound实例

    protected void Repeater3_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)//指触发对象的类型是DadaList里的基本行或是替换行(简单的说是Repeater里的所有数据项内容)          

             {
                    DataRowView drv = (DataRowView)e.Item.DataItem;
                    var row = (WebApplication1.ObjDateScr.DAL.DataSetPerson.T_UsersRow)drv.Row;
                    if (row.state == "禁用")
                    {
                        HtmlTableRow trRow = (HtmlTableRow)e.Item.FindControl("trRow");
                        trRow.Attributes["class"] = "trRow";//给<tr runat="server" class="trRow">的行添加属性
                        Button btn = (Button)e.Item.FindControl("disable");
                        btn.Visible = false;
                        Button btn2 = (Button)e.Item.FindControl("able");
                        btn2.Visible = true;

                    }
                    else if (row.state == "启用")
                    {
                        HtmlTableRow trRow = (HtmlTableRow)e.Item.FindControl("trRow");
                        trRow.Attributes["class"] = "";
                        Button btn = (Button)e.Item.FindControl("disable");
                        btn.Visible = true;
                        Button btn2 = (Button)e.Item.FindControl("able");
                        btn2.Visible = false;

                    }
                    else
                    {
                        throw new Exception("非法的状态");

                    }
                }
            }

  • 相关阅读:
    DLPAR中关于cpu资源的分配
    官网下载storage manager方法
    vsftpd中关于ftpusers和user_list两个文件的说明以及vsftpd.conf中的userlist_enable和userlist_deny两个配置项的解释
    Windows10搭建FTP服务器
    fdisk分区的起始扇区为什么是2048——linux 分区与启动的小故事
    P740SAS卡报错的处理
    linux 下route命令
    实验01:构建FTP服务器
    IBMx86 x3850 7143机器面板PCI灯亮
    css的选择器汇总
  • 原文地址:https://www.cnblogs.com/lzhp/p/2680820.html
Copyright © 2011-2022 走看看