日期:2014-05-19  浏览次数:20494 次

ItemDataBound

帮我看看那里错了
if(e.Item.ItemType   ==   ListItemType.AlternatingItem   ||   e.Item.ItemType   ==   ListItemType.Item)
{      
    ((LinkButton)(e.Item.Cells[7].Controls[0])).Attributes.Add( "onclick ", "return   confirm( '确认删除吗? ') ");
lbl   =   (Label)e.Item.FindControl( "lbl ");
DataRowView   drv   =(DataRowView)e.Item.DataItem;
date1       =     (DateTime)drv[ "jiezhitime "];       //取出数据库中的时间      
if(date1> DateTime.Now)
{
this.lbl.Text=drv[ "jiezhitime "].ToString();
}
                  else
{
this.lbl.Text= "过期 ";
}
}
提示:
this.lbl.Text=drv[ "jiezhitime "].ToString();未将对象引用设置到对象的实例


------解决方案--------------------
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
((LinkButton)(e.Item.Cells[7].Controls[0])).Attributes.Add( "onclick ", "return confirm( '确认删除吗? ') ");
Label lbl = (Label)e.Item.FindControl( "lbl "); //你的肯定有这个lbl哦
DataRowView drv =(DataRowView)e.Item.DataItem;
date1 = (DateTime)drv[ "jiezhitime "]; //取出数据库中的时间
if(date1> DateTime.Now)
{
this.lbl.Text=drv[ "jiezhitime "].ToString();
}
else
{
this.lbl.Text= "过期 ";
}
}
}
------解决方案--------------------
this.lbl ==> lbl 另要注意控件存在.