首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

Repeater 控件让满足条件的行变色,该怎么解决

2012-04-20 
Repeater 控件让满足条件的行变色protected void Repeater1_ItemDataBound(object sender, RepeaterItemEv

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;
}

热点排行