locked
CREATE RETRIEVE UPDATE - Checkbox Help! RRS feed

  • Question

  • User-691689463 posted

    Hello people! My project is killing me and i am desparate for help! Hopefully you guys can help me out!

    I am suppose to do CRU for my project. 

    Create.aspx

    For this page, i uses session to parse information from page to page till my final page before creating into my database. I have 3 checkboxes by the way. Textfield and Dropdownlist all are working fine except my Checkbox.

    At the pageLoad, i am looking for the IfElse logic such that when the user did not tick the checkbox, it will be reflected as untick in my final page so that NULL will be created in my database.

    Now my situation is, only 1 out of 3 boxes are ticked when it reaches my final page and, no matter what, all 3 checkboxes be it tick or not tick will be stored in my database. I need the IfElse logic to make my create sensible.

    Anybody can help? I tried but is wrong. ): The wrong codes are as followed.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using BusinessLayer;
    
    namespace PresentationLayer
    {
        public partial class OPCreate_Final : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                tb_opID.Text = (string)(Session["textbox1"].ToString());
                tb_opName.Text = (string)(Session["textbox2"].ToString());
                op_startDate.Text = (string)(Session["textbox3"].ToString());
                op_endDate.Text = (string)(Session["textbox4"].ToString());
                tb_opObjectives.Text = (string)(Session["textbox5"].ToString());
                tb_opTripCost.Text = (string)(Session["textbox6"].ToString());
                tb_opOtherCost.Text = (string)(Session["textbox7"].ToString());
                String pSEA = (string)Session["checkbox1"].ToString();
                if (pSEA == CheckBoxPSEA.Text)
                {
                    CheckBoxPSEA.Checked = true;
                }
                String fASOP = (string)Session["checkbox2"].ToString();
                if (fASOP == CheckBoxFASOP.Text)
                {
                    CheckBoxFASOP.Checked = true;
                }
                String kTPIOP = (string)Session["checkbox3"].ToString();
                if (kTPIOP == CheckBoxKTPIOP.Text)
                {
                    CheckBoxKTPIOP.Checked = true;
                }
                ddl_staff.Text = (string)Session["ddl1"].ToString();
                tb_nameOfTripGuide.Text = (string)Session["textbox8"].ToString();
                tb_descOfTripRole.Text = (string)Session["textbox9"].ToString();
                ddl_noOfParticipants.Text = (string)Session["ddl2"].ToString();
                tb_placeOfLodging.Text = (string)Session["textbox10"].ToString();
                ddl_airlineChoices.Text = (string)Session["ddl3"].ToString();
                tb_closingDate.Text = (string)Session["textbox11"].ToString();
                tb_instructions.Text = (string)Session["textbox12"].ToString();
                tb_travelAgent.Text = (string)Session["textbox13"].ToString();
                tb_contactPerson.Text = (string)Session["textbox14"].ToString();
                tb_officeNo.Text = (string)Session["textbox15"].ToString();
                tb_handphoneNo.Text = (string)Session["textbox16"].ToString();
            }
    
            protected void btn_create_Click(object sender, EventArgs e)
            {
                string opID = tb_opID.Text;
                string opName = tb_opName.Text;
                string opStartDate = op_startDate.Text;
                string opEndDate = op_endDate.Text;
                string opObjectives = tb_opObjectives.Text;
                string opTripCost = tb_opTripCost.Text;
                string opOtherCost = tb_opOtherCost.Text;
                string DBpsea = CheckBoxPSEA.Text;
                string DBfasop = CheckBoxFASOP.Text;
                string DBktpiop = CheckBoxKTPIOP.Text;
                string staffTripLeader = ddl_staff.SelectedValue;
                string tripGuideName = tb_nameOfTripGuide.Text;
                string tripGuideRole = tb_descOfTripRole.Text;
                string maxNoOfParticipants = ddl_noOfParticipants.SelectedValue;
                string placeOfLodging = tb_placeOfLodging.Text;
                string airlineChoices = ddl_airlineChoices.SelectedValue;
                string closingDateOfApplication = tb_closingDate.Text;
                string instructionsToApplicants = tb_instructions.Text;
                string travelAgentName = tb_travelAgent.Text;
                string travelAgentContactPerson = tb_contactPerson.Text;
                string officeNo = tb_officeNo.Text;
                string handphoneNo = tb_handphoneNo.Text;
                opBLL.createOPSuccess(opID, opName, opStartDate, opEndDate, opObjectives, opTripCost, opOtherCost, DBpsea, DBfasop, DBktpiop, staffTripLeader, tripGuideName, tripGuideRole, maxNoOfParticipants, placeOfLodging, airlineChoices, closingDateOfApplication, instructionsToApplicants, travelAgentName, travelAgentContactPerson, officeNo, handphoneNo);
            }
        }
    }

    Friday, January 27, 2012 10:50 PM

All replies

  • User339993961 posted

    You wrote the code to tick, but you did not write the code for untick, write for untick in else part.

    String pSEA = (string)Session["checkbox1"].ToString();
                if (pSEA == CheckBoxPSEA.Text)
                {
                    CheckBoxPSEA.Checked = true;
                }

    else

    CheckBoxPSEA.Checked = false;

                String fASOP = (string)Session["checkbox2"].ToString();
                if (fASOP == CheckBoxFASOP.Text)
                {
                    CheckBoxFASOP.Checked = true;
                }

    else

      CheckBoxFASOP.Checked = false;
                String kTPIOP = (string)Session["checkbox3"].ToString();
                if (kTPIOP == CheckBoxKTPIOP.Text)
                {
                    CheckBoxKTPIOP.Checked = true;
                }

      CheckBoxKTPIOP.Checked = false;

     

    If you still have a problem, let me know.

    Saturday, January 28, 2012 2:31 AM
  • User-691689463 posted

    Hey hello!

    Thanks for your reply. Was so happy to see help, at least it didnt make me give up on my project!

    Sad to say it is not working. What should i do? Is it the btn_create_click code that part got error? Anyway in my database table, the column name for the respective checkboxes are DBpsea, DBfasop and DBkptiop.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using BusinessLayer;
    
    namespace PresentationLayer
    {
        public partial class OPCreate_Final : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                tb_opID.Text = (string)(Session["textbox1"].ToString());
                tb_opName.Text = (string)(Session["textbox2"].ToString());
                op_startDate.Text = (string)(Session["textbox3"].ToString());
                op_endDate.Text = (string)(Session["textbox4"].ToString());
                tb_opObjectives.Text = (string)(Session["textbox5"].ToString());
                tb_opTripCost.Text = (string)(Session["textbox6"].ToString());
                tb_opOtherCost.Text = (string)(Session["textbox7"].ToString());
                string DBpsea = (string)Session["checkbox1"].ToString();
                if (DBpsea == CheckBoxPSEA.Text)
                {
                    CheckBoxPSEA.Checked = true;
                }
    
                else
    
                    CheckBoxPSEA.Checked = false;
    
                string DBfasop = (string)Session["checkbox2"].ToString();
                if (DBfasop == CheckBoxFASOP.Text)
                {
                    CheckBoxFASOP.Checked = true;
                }
    
                else
    
                    CheckBoxFASOP.Checked = false;
                string DBktpiop = (string)Session["checkbox3"].ToString();
                if (DBktpiop == CheckBoxKTPIOP.Text)
                {
                    CheckBoxKTPIOP.Checked = true;
                }
    
                CheckBoxKTPIOP.Checked = false;
                ddl_staff.Text = (string)Session["ddl1"].ToString();
                tb_nameOfTripGuide.Text = (string)Session["textbox8"].ToString();
                tb_descOfTripRole.Text = (string)Session["textbox9"].ToString();
                ddl_noOfParticipants.Text = (string)Session["ddl2"].ToString();
                tb_placeOfLodging.Text = (string)Session["textbox10"].ToString();
                ddl_airlineChoices.Text = (string)Session["ddl3"].ToString();
                tb_closingDate.Text = (string)Session["textbox11"].ToString();
                tb_instructions.Text = (string)Session["textbox12"].ToString();
                tb_travelAgent.Text = (string)Session["textbox13"].ToString();
                tb_contactPerson.Text = (string)Session["textbox14"].ToString();
                tb_officeNo.Text = (string)Session["textbox15"].ToString();
                tb_handphoneNo.Text = (string)Session["textbox16"].ToString();
            }
    
            protected void btn_create_Click(object sender, EventArgs e)
            {
                string opID = tb_opID.Text;
                string opName = tb_opName.Text;
                string opStartDate = op_startDate.Text;
                string opEndDate = op_endDate.Text;
                string opObjectives = tb_opObjectives.Text;
                string opTripCost = tb_opTripCost.Text;
                string opOtherCost = tb_opOtherCost.Text;
                string DBpsea = CheckBoxPSEA.Text;
                string DBfasop = CheckBoxFASOP.Text;
                string DBktpiop = CheckBoxKTPIOP.Text;
                string staffTripLeader = ddl_staff.SelectedValue;
                string tripGuideName = tb_nameOfTripGuide.Text;
                string tripGuideRole = tb_descOfTripRole.Text;
                string maxNoOfParticipants = ddl_noOfParticipants.SelectedValue;
                string placeOfLodging = tb_placeOfLodging.Text;
                string airlineChoices = ddl_airlineChoices.SelectedValue;
                string closingDateOfApplication = tb_closingDate.Text;
                string instructionsToApplicants = tb_instructions.Text;
                string travelAgentName = tb_travelAgent.Text;
                string travelAgentContactPerson = tb_contactPerson.Text;
                string officeNo = tb_officeNo.Text;
                string handphoneNo = tb_handphoneNo.Text;
                opBLL.createOPSuccess(opID, opName, opStartDate, opEndDate, opObjectives, opTripCost, opOtherCost, DBpsea, DBfasop, DBktpiop, staffTripLeader, tripGuideName, tripGuideRole, maxNoOfParticipants, placeOfLodging, airlineChoices, closingDateOfApplication, instructionsToApplicants, travelAgentName, travelAgentContactPerson, officeNo, handphoneNo);
            }
        }
    }

    Saturday, January 28, 2012 2:51 AM
  • User-691689463 posted

    I have got a problem and i wonder if it affect this.

    When i ticked all 3 checkboxes, only the 1st checkbox will appeared as ticked at my last page. The other 2 checkboxes was reflected as unticked.

    Erm, you got what i mean yeah? Because my create Session based. So i parse and parse information over.

    Saturday, January 28, 2012 3:07 AM
  • User-691689463 posted

    I cannot run my last page if none of the checkbox was think before hand.

    The session for my checkbox cannot be null. ARGHHHH.

    Saturday, January 28, 2012 3:23 AM
  • User339993961 posted

    Ok. I will go through the code and let you know.

    Saturday, January 28, 2012 3:30 AM
  • User339993961 posted

    Where are you assigning the values to the session variables?

    Saturday, January 28, 2012 3:31 AM
  • User-691689463 posted

    Will it be easier if i send you the file because it involves more than 1 page? Just asking.

    Anw, i am feeling really grateful for the help you gave! :)

    Saturday, January 28, 2012 3:31 AM
  • User-691689463 posted

    Because the information is passed from the previous page?

    Saturday, January 28, 2012 3:32 AM
  • User339993961 posted

    Ok, send, then i  can solve it.

    Saturday, January 28, 2012 3:33 AM
  • User-691689463 posted

    Hello! Have PM you. (:

    Saturday, January 28, 2012 3:39 AM
  • User339993961 posted

    What? I dint get you.

    Saturday, January 28, 2012 3:47 AM
  • User-691689463 posted

    erm i mean check your inbox.

    Saturday, January 28, 2012 3:49 AM
  • User339993961 posted

    send it on my mail id, its v_rajanireddy@rediff.com.

    The url which has been sent by you is blocked in my organization.

    Saturday, January 28, 2012 3:50 AM
  • User-691689463 posted

    Have sent it to you. (:

    Thank you so so much.

    Saturday, January 28, 2012 3:57 AM
  • User339993961 posted

    Ok. Checking.

    Saturday, January 28, 2012 4:02 AM
  • User-691689463 posted

    I thank you very very much.

    Saturday, January 28, 2012 4:03 AM
  • User339993961 posted

    What is your framework version? I am using 3.5 and it is not recognizing your sln file. I sent you mail.

    Saturday, January 28, 2012 4:17 AM
  • User-691689463 posted

    Anybody else can help me?

    Saturday, January 28, 2012 4:34 AM