c# - Object reference not set to an instance of an object -
i using following code check values added db table in checkboxlist, getting 'object reference not set instance of object' error here:
listitem currentcheckbox = chkbx.items.findbyvalue(rdr["memberid"].tostring());
here's code, help!
sqldatareader rdr = null; sqlconnection conn = new sqlconnection(getconnectionstring()); sqlcommand cmd5 = new sqlcommand("select memberid projectiterationmember projectiterationid in (select projectiterationid iterations projectid = '" + proj_id + "')", conn); try { conn.open(); rdr = cmd5.executereader(); checkboxlist chkbx = (checkboxlist)findcontrol("project_members"); while (rdr.read()) { listitem currentcheckbox = chkbx.items.findbyvalue(rdr["memberid"].tostring()); if (currentcheckbox != null) { currentcheckbox.selected = true; } } } { if (rdr != null) { rdr.close(); } if (conn != null) { conn.close(); } }
either rdr["memberid"]
returns null or chkbx
null control couldn't found. try rdr[0]
instead case, , in second case, make sure control found.
Comments
Post a Comment