asp.net - where to check the state of dynamically created checkboxes -
hello in programme need create dynamically checkboxlist items - got teh database.
the problem when clicking button should text cn checked checkboxes , should redirect user page
and have difficulty determining width of controls checkedore
if checked after added
so if write
if (mycheckbox.items[s].selected==true)
after line
page.findcontrol("form1").controls.add(mycheckbox); they not checked still false)
- on postback event (clicking button ) - know on postback event dynamic controls no longer exist)
here code
protected void ddlnumbertourists_selectedindexchanged(object sender, eventargs e) { int numtourists = convert.toint32(ddlnumbertourists.selecteditem.text); (int = 0; < numtourists; i++) { string connectionstring = "server=localhost\\sqlexpress;database=excursion;trusted_connection=true"; string query = "select extra_charge_id, excursion_id, amout, extra_charge_description extra_charges excursion_id=" + mynewstring; sqlconnection conn = new sqlconnection(connectionstring); sqlcommand cmd = new sqlcommand(query, conn); try { conn.open(); sqldatareader rd = cmd.executereader(); int s = 0; while (rd.read()) { mycheckbox.id = "chkblextracharge" + i.tostring() + s.tostring(); mycheckbox.items.add(rd["extra_charge_description"].tostring()); page.findcontrol("form1").controls.add(mycheckbox); s++; } }//end of try catch (exception ex) { } }//end of
i've implemented client-side check using jquery in online quiz engine (demo: http://webinfocentral.com): extract code snippet follows:
var _rows = $(this).find('tr'); (i = 0; < _rows.length; i++) { // find out if checkbox checked _checked = $(_rows[i]).find('input:checkbox').is(':checked'); }
Comments
Post a Comment