mardi 29 mars 2016

How to capture values of checkboxes using Viewstate

I have 2 checkboxes, one is called the approve and the other one reject. The purpose of each of the checkboxes is: 1. When the Approve checkbox is checked the comments need to be filled in and same is the case with the Reject checkbox. (These comments are saved in a History grid on the same page) 2. When both approve and reject have been unchecked: (this is the case when the user decides to change his/her mind and unchecks the approve checkbox and save, then the approve should delete all the previous approve comments and upon selecting the reject option, it should delete the last updated reject comments only. I have the logic for both of them and they work fine individually, but when both of them are used at the same time, only reject unchecked option works. Please note that, Oracle database is used for backend. Here's the code:

On page_load:

if (!this.cbReturn.Checked && !this.cbApproved.Checked)
                {
                    ViewState["Return"] = null;
                    ViewState["Approve"] = null;
                }

On approve_checkchanged

ViewState["Approve"] = cbApproved.ToString();

On Submit_click

for approve uncheck:

 if (!this.cbReturn.Checked && !this.cbApproved.Checked)
                    {
                         cReporter_Review = "N";

                        string tRow = "";
                        if (ViewState["Approve"] != null)
                            tRow = ViewState["Approve"].ToString();
                        else
                            tRow = this.radTBAcceptComments.Text;

                        DbServices dbService = new DbServices();

                        string connectionString = dbService.Connection.ConnectionString;

                        string querystring = "Delete from HSIP.FY_ST_QUESTION_COMMENTS_INFO q where q.state_code = " + strStateCode + " and q.record_type='Y' and q.display_number= " + numDisplayNumber + " and q.FY='2015'";



                        using (OracleConnection connection = new OracleConnection(connectionString))
                        {
                            using (OracleCommand command = new OracleCommand(querystring, connection))
                            {

                                connection.Open();

                                DataSet ds = dbService.GetDataSet(querystring, CmdType.SQL);
                                connection.Close();
                            }
                        }

                          btnNextQue_Click(this, new EventArgs());

                    }

Please let me know if I have to add anything else to the viewstate. I have approve query only, for reject it works, so I didn't post the code. Please let me know the condition which needs to be added so that on approve check changed (when unchecked and also reject unchecked) it should enter into this part of the logic currently the breakpoint doesn't hit through the above logic for approve. Please help me with the condition.

Thanks, Dimpy




Aucun commentaire:

Enregistrer un commentaire