Repeater 控件让满足条件的行变色
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
var peoplerow = (DataSet1.T_PeopleRow)drv.Row;
if (peoplerow.Age > 50)
{
TextBox txtAge = (TextBox)e.Item.FindControl("txtAge");
txtAge.BackColor = Color.Red;
}
}
var peoplerow = (DataSet1.T_PeopleRow)drv.Row;
未将对象引用设置到对象的实例,大牛们看看怎么解决?谢谢了~
[解决办法]
DataRowView drv = (DataRowView)e.Item.DataItem;
var peoplerow = Convert.ToInt32(drv["Age"]);
试试
[解决办法]
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//加一行判断
if(e.Item == null) //类似的,判断repeter该行不为空
{return;}
DataRowView drv = (DataRowView)e.Item.DataItem;
var peoplerow = (DataSet1.T_PeopleRow)drv.Row;
[解决办法]
你应该加
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
var peoplerow = (DataSet1.T_PeopleRow)drv.Row;
if (peoplerow.Age > 50)
{
TextBox txtAge = (TextBox)e.Item.FindControl("txtAge");
txtAge.BackColor = Color.Red;
}
}
[解决办法]
DataRowView drv = (DataRowView)e.Item.DataItem;
var peoplerow = Convert.ToInt32(drv["Age"]);
if (peoplerow> 50)
{
TextBox txtAge = (TextBox)e.Item.FindControl("txtAge");
txtAge.BackColor = Color.Red;
}