• 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("非法的状态");

                    }
                }
            }

  • 相关阅读:
    看到差距了,受打击
    数码相机选购指南(应小麻之作)
    sorry
    ACM集训第一天
    没事了,放心了,回到自己,又有些失落
    黑暗世界的一线光明

    无忧无虑的睡去,是一种奢华的享受(新)
    一些废话
    对事不对人
  • 原文地址:https://www.cnblogs.com/lzhp/p/2680820.html
Copyright © 2020-2023  润新知