c# - Error casting SqlDataReader DataItem to DataRowView on RowBound event of GridView -
i have gridview assign datasource , bind this:
protected void search(object sender, eventargs e) { using(sqlconnection con = new sqlconnection(constring)) using(sqlcommand com = new sqlcommand("xxx", con)) { com.commandtype = commandtype.storedprocedure; // parameter declarations here con.open(); sqldatareader rdr = com.executereader(); gvresults.datasource = rdr; gvresults.databind(); } }
there onrowbound method looks this:
protected void gvresults_onrowbound(object sender, gridviewroweventargs e) { gridviewrow row = e.row; if (row.rowtype != datacontrolrowtype.datarow) return; datarowview rowdata = (datarowview)row.dataitem; // fancy stuff happen here }
when line attempts cast row's dataitem datarowview reached error thrown reads:
unable cast object of type 'system.data.common.datarecordinternal' type 'system.data.datarowview'
i understand i'm not casting dataitem right kind of class, question what right class casting when datasource sqldatareader?
or on wrong track completely?
the correct type idatarecord
Comments
Post a Comment