protected void Attendance_gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ImageButton temp_edit = (ImageButton)e.Row.FindControl("lb_edit");
            temp_edit.CommandName = "Attendance_Edit";
            temp_edit.CommandArgument = e.Row.RowIndex.ToString();
            Label temp_tab = (Label)e.Row.FindControl("a_status_m");
            DataRowView temp_dv = (DataRowView)e.Row.DataItem;
            temp_tab.Text = AttendanceClass.ShowStatus(temp_dv.Row["a_status_m"].ToString());
            Label temp_tab_A = (Label)e.Row.FindControl("a_status_a");
            DataRowView temp_dv_A = (DataRowView)e.Row.DataItem;
            temp_tab_A.Text = AttendanceClass.ShowStatus(temp_dv_A.Row["a_status_a"].ToString());
        }    /////无法将类型为“Rs_Sysyem.Models.RS_Person”的对象强制转换为类型“System.Data.DataRowView”。
        if (e.Row.RowType == DataControlRowType.Pager)
        {
            Label Templb = (Label)e.Row.FindControl("Recordcount_lb");
            Templb.Text = _AttendanceManage.RecordCount;
            Templb = (Label)e.Row.FindControl("Pagecount_lb");
            Templb.Text = Attendance_gv.PageCount.ToString();
            Templb = (Label)e.Row.FindControl("abbPage_lb");
            Templb.Text = Convert.ToString(Attendance_gv.PageIndex + 1);
        }
    }

解决方案 »

  1.   

    要使用DataRowView好像应该用这个对象
    e.Row.NameContainer.DataItem
      

  2.   

    显然你绑定的不是 DataTable/DataView 
      

  3.   

    你绑定的是  List<Rs_Sysyem.Models.RS_Person> 之类的吧 Label temp_tab = (Label)e.Row.FindControl("a_status_m"); 
                //DataRowView temp_dv = (DataRowView)e.Row.DataItem; 
    Rs_Sysyem.Models.RS_Person p = (Rs_Sysyem.Models.RS_Person)e.Row.DataItem; 
                //temp_tab.Text = AttendanceClass.ShowStatus(temp_dv.Row["a_status_m"].ToString()); 
    temp_tab.Text = AttendanceClass.ShowStatus(p.YourPropertyName);