From my previous post I’m using a javascript to check some checkboxes which works fine. But then I have a button that puts some records in a database. Using the following code it doesn’t matter whether a checkbox is checked or not it is always gives me false.
bool first = true;
bool _IsPhone = false;
bool _IsLotus = false;
bool _IsRelationship = false;
bool _IsAdmin = false;
string _Country;
foreach (GridViewRow row in CountryAccessGrid.Rows)
{
CheckBox ch = ((CheckBox)row.FindControl("chkPhones"));
_Country = ((Label)row.FindControl("lblCountryShort")).Text;
_IsPhone = ((CheckBox)row.FindControl("chkPhones")).Checked;
_IsLotus = ((CheckBox)row.FindControl("chkLotus")).Checked;
_IsRelationship = ((CheckBox)row.FindControl("chkRelationship")).Checked;
_IsAdmin = ((CheckBox)row.FindControl("chkIsAdmin")).Checked;
if (_IsPhone == true || _IsLotus == true || _IsRelationship == true || _IsRelationship == true || _IsAdmin == true)
{
cntr = cntr + 1;
if (!first)
{
insertaccess += " UNION ALL ";
}
insertaccess += " SELECT " + _UserID + ", '" + _Country + "', " + _IsPhone + ", " + _IsLotus + ", " + _IsRelationship + ", " + _IsAdmin;
first = false;
}
}
How to get a state of a checkbox, please?
To be able to asnwer this question we have to know following:
DataSourceDataBindit to theGridView?But i assume that you always
DataBindit inPage_Loadeven if it’s a postback. That would override the values and prevents the events from being triggered.So you have to use the
IsPostBackproperty: