Brian
asked on
How to retrieve RadioButtonList Values
Hello Experts,
I'm creating an application with the following specification below. Please see what I need help with below the specifications of my application.
Specifications:
- User must select a value from a RadioButtonList Control. The values are retrieved from a DB to the RadioButtonList Control.
- If a user select the word ONSITE which has a value of 20000 then it will display a TextBox Control from a Panel Control called panel_Onsite.
- If a user select the word OFFISTE which has a value of 20001 then it will display a TextBox and FileUpload Control from a Panel Control called panel_Offsite.
What I need help with:
- I need to display the selected value from the RadioButtonList Control along with the Controls within the Panel Control from the selected RadioButtonList Control on Page_Load.
I have all steps working fine except for the step mentioned above.
I'm creating an application with the following specification below. Please see what I need help with below the specifications of my application.
Specifications:
- User must select a value from a RadioButtonList Control. The values are retrieved from a DB to the RadioButtonList Control.
- If a user select the word ONSITE which has a value of 20000 then it will display a TextBox Control from a Panel Control called panel_Onsite.
- If a user select the word OFFISTE which has a value of 20001 then it will display a TextBox and FileUpload Control from a Panel Control called panel_Offsite.
What I need help with:
- I need to display the selected value from the RadioButtonList Control along with the Controls within the Panel Control from the selected RadioButtonList Control on Page_Load.
I have all steps working fine except for the step mentioned above.
rbList.SelectedItem.Text;
ASKER
Hi informaniac,
I was able to use the following below to retrieve the value for the RadioButtonList Control. IS this the correct way? Also, my other problem that I mentioned is that when the Page Loads for the first time I need to put a selection in the RadioButtonList control but also display the Panel from the RadioButtonList control along with that Panels Controls and it's data.
protected void Page_Load(object sender, EventArgs e)
{
lblVerificationFormFileNam e.Visible = false;
lblFileSize.Visible = false;
lblInsertError.Visible = false;
panel_Onsite.Visible = false;
panel_Offsite.Visible = false;
string FirstName = Convert.ToString(Session[" fname"]);
string LastName = Convert.ToString(Session[" lname"]);
string EmpID = Convert.ToString(Session[" empid"]);
lblFullNameSession.Text = "Hello, " + FirstName + " " + LastName;
hf_emp_id.Value = EmpID;
if (!IsPostBack)
{
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["We llnessTrac ker"].Conn ectionStri ng);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "RetrievePreventiveHealthS creeningsV aluesByEMP _ID";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
cmd.Parameters.AddWithValu e("@emp_id ", SqlDbType.Int).Value = EmpID;
DataTable dtPreventiveScreenings = new DataTable("Modify");
SqlDataAdapter adp = new SqlDataAdapter();
try
{
conn.Open();
adp.SelectCommand = cmd;
adp.Fill(dtPreventiveScree nings);
if ((dtPreventiveScreenings != null))
{
DataRow data = dtPreventiveScreenings.Row s[0];
hf_phs_id.Value = data["phs_id"].ToString();
lblVerificationFormFileNam e.Text = "No file is uploaded";
foreach (DataRow Row in dtPreventiveScreenings.Row s)
{
if (!(Row.IsNull("psv_id")))
{
rbl_PreventiveHealthScreen ings.Items .FindByVal ue(Row["ps v_id"].ToS tring()).S elected = true;
}
}
txtOnsiteDateCompleted.Tex t = string.Empty;
if (data["phs_date"] != DBNull.Value && !string.IsNullOrEmpty(Conv ert.ToStri ng(data["p hs_date"]) ))
txtOnsiteDateCompleted.Tex t = Convert.ToDateTime(data["p hs_date"]) .ToShortDa teString() ;
txtOffsiteDateCompleted.Te xt = string.Empty;
if (data["phs_date"] != DBNull.Value && !string.IsNullOrEmpty(Conv ert.ToStri ng(data["p hs_date"]) ))
txtOffsiteDateCompleted.Te xt = Convert.ToDateTime(data["p hs_date"]) .ToShortDa teString() ;
string phs_pdf_filename = null;
if (data["phs_pdf_filename"] != DBNull.Value)
{
phs_pdf_filename = data["phs_pdf_filename"].T oString();
}
if (!string.IsNullOrEmpty(phs _pdf_filen ame))
{
lblVerificationFormFileNam e.Visible = true;
lblVerificationFormFileNam e.Text = "Your File has been uploaded: " + phs_pdf_filename;
}
if (data["phs_section_complet e"].ToStri ng() == "1")
{
btn_PreventiveScreenings.E nabled = false;
cb_PreventiveScreenings.Ch ecked = true;
}
else
{
cb_PreventiveScreenings.Ch ecked = false;
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
}
I was able to use the following below to retrieve the value for the RadioButtonList Control. IS this the correct way? Also, my other problem that I mentioned is that when the Page Loads for the first time I need to put a selection in the RadioButtonList control but also display the Panel from the RadioButtonList control along with that Panels Controls and it's data.
protected void Page_Load(object sender, EventArgs e)
{
lblVerificationFormFileNam
lblFileSize.Visible = false;
lblInsertError.Visible = false;
panel_Onsite.Visible = false;
panel_Offsite.Visible = false;
string FirstName = Convert.ToString(Session["
string LastName = Convert.ToString(Session["
string EmpID = Convert.ToString(Session["
lblFullNameSession.Text = "Hello, " + FirstName + " " + LastName;
hf_emp_id.Value = EmpID;
if (!IsPostBack)
{
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "RetrievePreventiveHealthS
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
cmd.Parameters.AddWithValu
DataTable dtPreventiveScreenings = new DataTable("Modify");
SqlDataAdapter adp = new SqlDataAdapter();
try
{
conn.Open();
adp.SelectCommand = cmd;
adp.Fill(dtPreventiveScree
if ((dtPreventiveScreenings != null))
{
DataRow data = dtPreventiveScreenings.Row
hf_phs_id.Value = data["phs_id"].ToString();
lblVerificationFormFileNam
foreach (DataRow Row in dtPreventiveScreenings.Row
{
if (!(Row.IsNull("psv_id")))
{
rbl_PreventiveHealthScreen
}
}
txtOnsiteDateCompleted.Tex
if (data["phs_date"] != DBNull.Value && !string.IsNullOrEmpty(Conv
txtOnsiteDateCompleted.Tex
txtOffsiteDateCompleted.Te
if (data["phs_date"] != DBNull.Value && !string.IsNullOrEmpty(Conv
txtOffsiteDateCompleted.Te
string phs_pdf_filename = null;
if (data["phs_pdf_filename"] != DBNull.Value)
{
phs_pdf_filename = data["phs_pdf_filename"].T
}
if (!string.IsNullOrEmpty(phs
{
lblVerificationFormFileNam
lblVerificationFormFileNam
}
if (data["phs_section_complet
{
btn_PreventiveScreenings.E
cb_PreventiveScreenings.Ch
}
else
{
cb_PreventiveScreenings.Ch
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, that may work. I did not think of that. Can you help me implement that?
ASKER
@informaniac,
Can you still help with this?
Can you still help with this?
Sorry mate. It was 1am when I had replied to you. :). So how can I help you with implementing this. What exactly are you not able to get.
You said that you were able to implement the logic, only thing is you were not able to do it in the pageload. Can you show some of that code here
You said that you were able to implement the logic, only thing is you were not able to do it in the pageload. Can you show some of that code here
ASKER
Hi informaniac,
No worry, I wasn't sure if you where still able to assist. Thank you for replying back and helping out. I was able to figure it out late last night after I made my last post. But would appreciate it if you could look over the code I implemented to see if I'm doing it correctly and maybe you have a better way that you can show me.
Please notice the following code below this line. This is what I added below. This is how I'm displaying the RadioButtonList value from the DB along with displaying the Panel Control that is related to the selected RadioButtonList value along with the Panel's Controls.
if (data["psv_id"].ToString() == "20000")
{
panel_Onsite.Visible = true;
rbl_PreventiveHealthScreen ings.Items .FindByVal ue(data["p sv_id"].To String()). Selected = true;
}
if (data["psv_id"].ToString() == "20001")
{
panel_Offsite.Visible = true;
rbl_PreventiveHealthScreen ings.Items .FindByVal ue(data["p sv_id"].To String()). Selected = true;
}
protected void Page_Load(object sender, EventArgs e)
{
lblVerificationFormFileNam e.Visible = false;
lblVerificationFormTypeErr or.Visible = false;
lblFileSize.Visible = false;
lblInsertError.Visible = false;
panel_Onsite.Visible = false;
panel_Offsite.Visible = false;
EmployeeLoginInfo();
SectionsCompleted();
RetrievePreventiveHealthSc reeningVal ues();
string FirstName = Convert.ToString(Session[" fname"]);
string LastName = Convert.ToString(Session[" lname"]);
string EmpID = Convert.ToString(Session[" empid"]);
lblFullNameSession.Text = "Hello, " + FirstName + " " + LastName;
hf_emp_id.Value = EmpID;
if (!IsPostBack)
{
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["We llnessTrac ker"].Conn ectionStri ng);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "RetrievePreventiveHealthS creeningsV aluesByEMP _ID";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
// cmd.Parameters.AddWithValu e("@emp_id ", SqlDbType.Int).Value = emp_id;
cmd.Parameters.AddWithValu e("@emp_id ", SqlDbType.Int).Value = EmpID;
DataTable dtPreventiveScreenings = new DataTable("Modify");
SqlDataAdapter adp = new SqlDataAdapter();
try
{
conn.Open();
adp.SelectCommand = cmd;
adp.Fill(dtPreventiveScree nings);
if ((dtPreventiveScreenings != null))
{
DataRow data = dtPreventiveScreenings.Row s[0];
hf_phs_id.Value = data["phs_id"].ToString();
lblVerificationFormFileNam e.Text = "No file is uploaded";
//foreach (DataRow Row in dtPreventiveScreenings.Row s)
//{
// if (!(Row.IsNull("psv_id")))
// {
// rbl_PreventiveHealthScreen ings.Items .FindByVal ue(Row["ps v_id"].ToS tring()).S elected = true;
// }
//}
if (data["psv_id"].ToString() == "20000")
{
panel_Onsite.Visible = true;
rbl_PreventiveHealthScreen ings.Items .FindByVal ue(data["p sv_id"].To String()). Selected = true;
}
if (data["psv_id"].ToString() == "20001")
{
panel_Offsite.Visible = true;
rbl_PreventiveHealthScreen ings.Items .FindByVal ue(data["p sv_id"].To String()). Selected = true;
}
txtOnsiteDateCompleted.Tex t = string.Empty;
if (data["phs_date"] != DBNull.Value && !string.IsNullOrEmpty(Conv ert.ToStri ng(data["p hs_date"]) ))
txtOnsiteDateCompleted.Tex t = Convert.ToDateTime(data["p hs_date"]) .ToShortDa teString() ;
txtOffsiteDateCompleted.Te xt = string.Empty;
if (data["phs_date"] != DBNull.Value && !string.IsNullOrEmpty(Conv ert.ToStri ng(data["p hs_date"]) ))
txtOffsiteDateCompleted.Te xt = Convert.ToDateTime(data["p hs_date"]) .ToShortDa teString() ;
string phs_pdf_filename = null;
if (data["phs_pdf_filename"] != DBNull.Value)
{
phs_pdf_filename = data["phs_pdf_filename"].T oString();
}
if (!string.IsNullOrEmpty(phs _pdf_filen ame))
{
lblVerificationFormFileNam e.Visible = true;
lblVerificationFormFileNam e.Text = "Your File has been uploaded: " + phs_pdf_filename;
}
if (data["phs_section_complet e"].ToStri ng() == "1")
{
btn_PreventiveScreenings.E nabled = false;
cb_PreventiveScreenings.Ch ecked = true;
}
else
{
cb_PreventiveScreenings.Ch ecked = false;
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
}
No worry, I wasn't sure if you where still able to assist. Thank you for replying back and helping out. I was able to figure it out late last night after I made my last post. But would appreciate it if you could look over the code I implemented to see if I'm doing it correctly and maybe you have a better way that you can show me.
Please notice the following code below this line. This is what I added below. This is how I'm displaying the RadioButtonList value from the DB along with displaying the Panel Control that is related to the selected RadioButtonList value along with the Panel's Controls.
if (data["psv_id"].ToString()
{
panel_Onsite.Visible = true;
rbl_PreventiveHealthScreen
}
if (data["psv_id"].ToString()
{
panel_Offsite.Visible = true;
rbl_PreventiveHealthScreen
}
protected void Page_Load(object sender, EventArgs e)
{
lblVerificationFormFileNam
lblVerificationFormTypeErr
lblFileSize.Visible = false;
lblInsertError.Visible = false;
panel_Onsite.Visible = false;
panel_Offsite.Visible = false;
EmployeeLoginInfo();
SectionsCompleted();
RetrievePreventiveHealthSc
string FirstName = Convert.ToString(Session["
string LastName = Convert.ToString(Session["
string EmpID = Convert.ToString(Session["
lblFullNameSession.Text = "Hello, " + FirstName + " " + LastName;
hf_emp_id.Value = EmpID;
if (!IsPostBack)
{
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "RetrievePreventiveHealthS
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
// cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
DataTable dtPreventiveScreenings = new DataTable("Modify");
SqlDataAdapter adp = new SqlDataAdapter();
try
{
conn.Open();
adp.SelectCommand = cmd;
adp.Fill(dtPreventiveScree
if ((dtPreventiveScreenings != null))
{
DataRow data = dtPreventiveScreenings.Row
hf_phs_id.Value = data["phs_id"].ToString();
lblVerificationFormFileNam
//foreach (DataRow Row in dtPreventiveScreenings.Row
//{
// if (!(Row.IsNull("psv_id")))
// {
// rbl_PreventiveHealthScreen
// }
//}
if (data["psv_id"].ToString()
{
panel_Onsite.Visible = true;
rbl_PreventiveHealthScreen
}
if (data["psv_id"].ToString()
{
panel_Offsite.Visible = true;
rbl_PreventiveHealthScreen
}
txtOnsiteDateCompleted.Tex
if (data["phs_date"] != DBNull.Value && !string.IsNullOrEmpty(Conv
txtOnsiteDateCompleted.Tex
txtOffsiteDateCompleted.Te
if (data["phs_date"] != DBNull.Value && !string.IsNullOrEmpty(Conv
txtOffsiteDateCompleted.Te
string phs_pdf_filename = null;
if (data["phs_pdf_filename"] != DBNull.Value)
{
phs_pdf_filename = data["phs_pdf_filename"].T
}
if (!string.IsNullOrEmpty(phs
{
lblVerificationFormFileNam
lblVerificationFormFileNam
}
if (data["phs_section_complet
{
btn_PreventiveScreenings.E
cb_PreventiveScreenings.Ch
}
else
{
cb_PreventiveScreenings.Ch
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
}
ASKER
@informaniac,
Hi, can you please over look what I added. I would like to award you points but wanted to ask you that one last question.
Hi, can you please over look what I added. I would like to award you points but wanted to ask you that one last question.
ASKER
@informaniac
Can you please answer my question in post ID: 38320691 before I close this post??
Can you please answer my question in post ID: 38320691 before I close this post??