GridView中的RowDataBound事件

昨天我在使用GridView中的RowDataBound事件的时候,老是报错:

"Object reference not set to an instance of an object."

 

我一看,可不是吗!

忘记了加入"if(e.Row.RowType == DataControlRowType.DataRow)"的判断,郁闷啊,郁闷!

代码如下:

///

/// RowDataBound event of GridView /// /// /// protected void TelephoneView_RowDataBound(object sender, GridViewRowEventArgs e) { //Must judge e.Row.RowType equals DateControlRowType.DataRow or not, //because e.Row.DataItem need the judge. if(e.Row.RowType == DataControlRowType.DataRow) { DataRowView drv = (DataRowView)( e.Row.DataItem ); if(drv["A"].ToString().Equals("True")) { e.Row.FindControl("row").Visible = false; } } }

 

另附   GridView的RowDataBound和DataGrid的ItemDataBound事件的比较网址

http://www.cnblogs.com/aiouluosi/archive/2007/07/26/832525.html

你可能感兴趣的:(.NET,菜鸟)