![](https://pic002.cnblogs.com/images/2012/374613/2012030218265184.jpg)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using repeater练习.DataSet1TableAdapters;
using System.Web.UI.HtmlControls;
namespace repeater练习
{
public partial class repeater练习 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//不加则e.Item.DataItem为空值(类型为header可调试查找)报错;没有设AlternatingItem但偶数行也识别为e.Item.ItemType == ListItemType.AlternatingItem
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
var userRow = (DataSet1.StatusRow)drv.Row;
if (userRow.status == "禁用")
{
HtmlTableRow htr = (HtmlTableRow)e.Item.FindControl("tr1");
htr.Attributes["class"] = "warning";
Button btn = (Button)e.Item.FindControl("Disable");
btn.Visible=false;
}
else if (userRow.status == "启用")
{
HtmlTableRow htr = (HtmlTableRow)e.Item.FindControl("tr1");
htr.Attributes["class"] = "";
Button btn = (Button)e.Item.FindControl("Enable");
btn.Visible = false;
}
else
{
throw new Exception("状态值非法");
}
}
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "btn1")//启用
{
int i = Convert.ToInt32(e.CommandArgument);
new StatusTableAdapter().Enable(i);
}
else//禁用
{
int i = Convert.ToInt32(e.CommandArgument);
new StatusTableAdapter().Disable(i);
}
Repeater1.DataBind();//刷新数据
}
}
}