c# - Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource -
i trying fill 1 details view gridview selected index changing event,but got error,plz me
public void viewdetailsnew(decimal decdv) { subjectinfo infosubject = new subjectinfo(); subjectsp spcubject = new subjectsp(); dvsubject.datasource = spcubject.subjectviewdetails(decdv); dvsubject.databind(); mvsubject.activeviewindex = 1; } public subjectinfo subjectviewdetails(decimal decsubjectid) { subjectinfo infosubject = new subjectinfo(); sqldatareader sqlreader = null; try { if (sqlcon.state == connectionstate.closed) { sqlcon.open(); } sqlcommand sqlcmd = new sqlcommand("subjectview", sqlcon); sqlcmd.commandtype = commandtype.storedprocedure; sqlcmd.parameters.add("@subjectid", sqldbtype.decimal).value = decsubjectid; sqlreader = sqlcmd.executereader(); while (sqlreader.read()) { infosubject.subjectid = decimal.parse(sqlreader["subjectid"].tostring()); infosubject.subjectname = sqlreader["subjectname"].tostring(); infosubject.shortname = sqlreader["shortname"].tostring(); } } catch { throw; } { sqlreader.close(); sqlcon.close(); } return infosubject; } protected void gvviewsubject_selectedindexchanging(object sender, gridviewselecteventargs e) { viewstate["subjectid"] = gvviewsubject.datakeys[e.newselectedindex]["subjectid"].tostring(); decimal decdv = decimal.parse(viewstate["subjectid"].tostring()); viewdetailsnew(decdv); }
you trying bind single object when need collection or ienumerable
try this
public ienumerable<subjectinfo> subjectviewdetails(decimal decsubjectid) { var list = new list<subjectinfo>(); try { if (sqlcon.state == connectionstate.closed) { sqlcon.open(); } sqlcommand sqlcmd = new sqlcommand("subjectview", sqlcon); sqlcmd.commandtype = commandtype.storedprocedure; sqlcmd.parameters.add("@subjectid", sqldbtype.decimal).value = decsubjectid; using (var sqlreader = sqlcmd.executereader()) { while (sqlreader.read()) { subjectinfo infosubject = new subjectinfo(); infosubject.subjectid = decimal.parse(sqlreader["subjectid"].tostring()); infosubject.subjectname = sqlreader["subjectname"].tostring(); infosubject.shortname = sqlreader["shortname"].tostring(); list.add(infosubject); } } } catch { throw; } { sqlcon.close(); } return list; }
Comments
Post a Comment