asp.net - how to update database colum with checkbox in gridview vb.net -
i have checkbox in gridview rows...and have database column name "active" default value "1"
i bind checkbox database colum active...
when click on checkbox default checked because default value of active in dbase column 1 ..
i want when uncheck checkbox value updated on active column of selected row 0...and checkbox remains unchecked....
i have code sippet not working
protected sub gridview1_rowdatabound(byval sender object, byval e system.web.ui.webcontrols.gridviewroweventargs) handles gridview1.rowdatabound each myrow gridviewrow in gridview1.rows 'find checkbox dim chk1 checkbox = directcast(myrow.findcontrol("checkbox1"), checkbox) dim id hiddenfield = directcast(myrow.findcontrol("hiddenfield1"), hiddenfield) dim active hiddenfield = directcast(myrow.findcontrol("hiddenfield3"), hiddenfield) dim sqldata new mysql.data.mysqlclient.mysqlconnection("server=localhost;user id=root;persist security info=true;database=clixngo") dim cmdselect new mysql.data.mysqlclient.mysqlcommand("select * my_state id='" & id.value & "'", sqldata) sqldata.open() dim dtrreader mysql.data.mysqlclient.mysqldatareader = cmdselect.executereader() if dtrreader.hasrows while dtrreader.read() chk1.checked = dtrreader("active") end while else end if dtrreader.close() sqldata.close() next end sub protected sub checkbox1_checkedchanged(byval sender object, byval e system.eventargs) each myrow gridviewrow in gridview1.rows dim chk1 checkbox = directcast(myrow.findcontrol("checkbox1"), checkbox) dim id hiddenfield = directcast(myrow.findcontrol("hiddenfield1"), hiddenfield) dim active hiddenfield = directcast(myrow.findcontrol("hiddenfield3"), hiddenfield) if chk1.checked = true sqldatasource1.updateparameters("id").defaultvalue = id.value sqldatasource1.updateparameters("active").defaultvalue = "1" sqldatasource1.updateparameters("state").defaultvalue = "andaman , nicobar" sqldatasource1.update() elseif chk1.checked = false sqldatasource1.updateparameters("id").defaultvalue = id.value sqldatasource1.updateparameters("active").defaultvalue = "0" sqldatasource1.updateparameters("state").defaultvalue = "andaman , nicobar" sqldatasource1.update() end if next end sub
Comments
Post a Comment