Repeater1_ItemDataBound绑定事件

时间:2021-11-23 08:06:26

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
        {
            object obj = ((System.Data.DataRowView)(e.Item.DataItem)).Row.ItemArray[21];//通过调试e.Item找到
            HtmlGenericControl span1 = (HtmlGenericControl)e.Item.FindControl("sp1");//在repeater的外面给一个标签id,根据此类型判断标签类型
            HtmlGenericControl span2 = (HtmlGenericControl)e.Item.FindControl("sp2");
            if (obj.ToString() == "0")
            {
                span1.Visible = true;
                span2.Visible = false;
            }
            else
            {
                span1.Visible = false;
                span2.Visible = true;
            }
          
        }
    }