Brian
asked on
How to display Check in CheckBox Control
Hello EE,
I have the following CodeBehind below and I would like to display a Check in my CheckBox Control during Page_Load if the value for the CheckBox Control is 1 in the DB.
protected void Page_Load(object sender, EventArgs e)
{
hf_AppID.Value = Session["pi_id"].ToString( );
if (!IsPostBack)
{
int pi_id = Convert.ToInt32(Session["p i_id"]);
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["We llnessChoi ce"].Conne ctionStrin g);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_RetrieveAn nualPhysic alValuesBy PI_ID";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
cmd.Parameters.AddWithValu e("@pi_id" , SqlDbType.Int).Value = pi_id;
DataTable dtModify = new DataTable("Modify");
SqlDataAdapter adp = new SqlDataAdapter();
try
{
conn.Open();
adp.SelectCommand = cmd;
adp.Fill(dtModify);
if ((dtModify != null))
{
DataRow data = dtModify.Rows[0];
hf_ap_id.Value = data["ap_id"].ToString();
txtPhysicalDateCompleted.T ext = Convert.ToDateTime(data["a p_date"]). ToShortDat eString();
lblFileNameUploaded.Text = "Your File has been uploaded: " + data["ap_pdf_filename"].To String();
if (data["ap_section_complete "].ToStrin g() == "1")
{
btn_SaveAnnualPhysical.Ena bled = false;
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
}
I have the following CodeBehind below and I would like to display a Check in my CheckBox Control during Page_Load if the value for the CheckBox Control is 1 in the DB.
protected void Page_Load(object sender, EventArgs e)
{
hf_AppID.Value = Session["pi_id"].ToString(
if (!IsPostBack)
{
int pi_id = Convert.ToInt32(Session["p
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_RetrieveAn
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
cmd.Parameters.AddWithValu
DataTable dtModify = new DataTable("Modify");
SqlDataAdapter adp = new SqlDataAdapter();
try
{
conn.Open();
adp.SelectCommand = cmd;
adp.Fill(dtModify);
if ((dtModify != null))
{
DataRow data = dtModify.Rows[0];
hf_ap_id.Value = data["ap_id"].ToString();
txtPhysicalDateCompleted.T
lblFileNameUploaded.Text = "Your File has been uploaded: " + data["ap_pdf_filename"].To
if (data["ap_section_complete
{
btn_SaveAnnualPhysical.Ena
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
}
ASKER
Hi discrupt,
Below is my code. What i'm trying to accomplish is to disable the Button Control to prevent users from submitting more data if the ChecBox Control labeled (cb_AnnualPhysical) is equal to "1" in the DB and if so disable Button Control labeled (btn_SaveAnnualPhysical) and place Check in CheckBox Control. This all needed to happen in Page_Load. So far it works as I needed but perhaps you can look it over and give me your feedback.
protected void Page_Load(object sender, EventArgs e)
{
hf_AppID.Value = Session["pi_id"].ToString( );
if (!IsPostBack)
{
int pi_id = Convert.ToInt32(Session["p i_id"]);
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["We llnessChoi ce"].Conne ctionStrin g);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_RetrieveAn nualPhysic alValuesBy PI_ID";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
cmd.Parameters.AddWithValu e("@pi_id" , SqlDbType.Int).Value = pi_id;
DataTable dtModify = new DataTable("Modify");
SqlDataAdapter adp = new SqlDataAdapter();
try
{
conn.Open();
adp.SelectCommand = cmd;
adp.Fill(dtModify);
if ((dtModify != null))
{
DataRow data = dtModify.Rows[0];
hf_ap_id.Value = data["ap_id"].ToString();
txtPhysicalDateCompleted.T ext = Convert.ToDateTime(data["a p_date"]). ToShortDat eString();
lblFileNameUploaded.Text = "Your File has been uploaded: " + data["ap_pdf_filename"].To String();
if (data["ap_section_complete "].ToStrin g() == "1")
{
btn_SaveAnnualPhysical.Ena bled = false;
cb_AnnualPhysical.Checked = true;
}
else
{
cb_AnnualPhysical.Checked = false;
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
.. code removed for brevity
}
Below is my code. What i'm trying to accomplish is to disable the Button Control to prevent users from submitting more data if the ChecBox Control labeled (cb_AnnualPhysical) is equal to "1" in the DB and if so disable Button Control labeled (btn_SaveAnnualPhysical) and place Check in CheckBox Control. This all needed to happen in Page_Load. So far it works as I needed but perhaps you can look it over and give me your feedback.
protected void Page_Load(object sender, EventArgs e)
{
hf_AppID.Value = Session["pi_id"].ToString(
if (!IsPostBack)
{
int pi_id = Convert.ToInt32(Session["p
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_RetrieveAn
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
cmd.Parameters.AddWithValu
DataTable dtModify = new DataTable("Modify");
SqlDataAdapter adp = new SqlDataAdapter();
try
{
conn.Open();
adp.SelectCommand = cmd;
adp.Fill(dtModify);
if ((dtModify != null))
{
DataRow data = dtModify.Rows[0];
hf_ap_id.Value = data["ap_id"].ToString();
txtPhysicalDateCompleted.T
lblFileNameUploaded.Text = "Your File has been uploaded: " + data["ap_pdf_filename"].To
if (data["ap_section_complete
{
btn_SaveAnnualPhysical.Ena
cb_AnnualPhysical.Checked = true;
}
else
{
cb_AnnualPhysical.Checked = false;
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
.. code removed for brevity
}
Looks good to me!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, Thank you for looking it over!
Checkbox1.checked = true;
what exactly are you stuck on?