在GridView dtg_search的RowDataBound方法中 怎样避免用Index,因为一旦SQL语句检索顺序或者字段个数发生改变 这个会出现很多隐患。个人觉得不应该这么做,但又不知道好的解决方案,望高手指点一二……谢!
protected void dtg_search_RowDataBound(object sender, GridViewRowEventArgs e)
string row_status = IsNull(((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[5]);//个人觉得很不好
------解决方案--------------------------------------------------------
改成这样试试:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
string row_status = null;
object obj = ((System.Data.DataRowView)(e.Row.DataItem)).Row[ "status "];
if (obj != null)
{
row_status = obj.ToString();
}
}