コード例 #1
0
    /// <summary>
    /// Handles the RowDeleting event of the gvVisaDetails control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewDeleteEventArgs"/> instance containing the event data.</param>
    protected void gvVisaDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int     deleteRowIndex = 0;
        int     rowIndex       = -1;
        Boolean Flag           = false;

        BusinessEntities.VisaDetails objVisaDetails = new BusinessEntities.VisaDetails();

        deleteRowIndex = e.RowIndex;

        objVisaDetails = (BusinessEntities.VisaDetails)VisaDetailsCollection.Item(deleteRowIndex);
        if (objVisaDetails.Mode == 1)
        {
            Flag = true;
        }
        objVisaDetails.Mode = 3;

        if (ViewState[VISADETAILSDELETE] != null)
        {
            BusinessEntities.RaveHRCollection objDeleteVisaDetailsCollection = (BusinessEntities.RaveHRCollection)ViewState[VISADETAILSDELETE];
            objDeleteVisaDetailsCollection.Add(objVisaDetails);

            ViewState[VISADETAILSDELETE] = objDeleteVisaDetailsCollection;
        }
        else
        {
            BusinessEntities.RaveHRCollection objDeleteVisaDetailsCollection1 = new BusinessEntities.RaveHRCollection();

            objDeleteVisaDetailsCollection1.Add(objVisaDetails);

            ViewState[VISADETAILSDELETE] = objDeleteVisaDetailsCollection1;
        }

        VisaDetailsCollection.RemoveAt(deleteRowIndex);

        ViewState[DELETEROWINDEX] = deleteRowIndex;

        DoDataBind();

        if (ViewState[ROWINDEX] != null)
        {
            rowIndex = Convert.ToInt32(ViewState[ROWINDEX].ToString());
            //check edit index with deleted index if edit index is greater than or equal to delete index then rowindex decremented.
            if (rowIndex != -1 && deleteRowIndex <= rowIndex)
            {
                rowIndex--;
                //store the rowindex in viewstate.
                ViewState[ROWINDEX] = rowIndex;
            }

            ImageButton btnImg = (ImageButton)gvVisaDetails.Rows[rowIndex].FindControl(IMGBTNDELETE);
            btnImg.Enabled = false;

            //Disabling all the edit buttons.
            for (int i = 0; i < gvVisaDetails.Rows.Count; i++)
            {
                if (rowIndex != i)
                {
                    ImageButton btnImgEdit = (ImageButton)gvVisaDetails.Rows[i].FindControl(IMGBTNEDIT);
                    btnImgEdit.Enabled = false;
                }
            }
        }
        if (gvVisaDetails.Rows[0].Cells[0].Text == NO_RECORDS_FOUND_MESSAGE && Flag == true)
        {
            btnAddRow.Text = CommonConstants.BTN_Save;
        }
        HfIsDataModified.Value = CommonConstants.YES;
    }
コード例 #2
0
    /// <summary>
    /// Handles the Click event of the btnUpdateRow control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void btnUpdateRow_Click(object sender, EventArgs e)
    {
        if (ValidateVisaControls())
        {
            int rowIndex       = 0;
            int deleteRowIndex = -1;

            if (ViewState[DELETEROWINDEX] != null)
            {
                deleteRowIndex = Convert.ToInt32(ViewState[DELETEROWINDEX].ToString());
            }

            //Update the grid view according the row, which is selected for editing.
            if (ViewState[ROWINDEX] != null)
            {
                rowIndex = Convert.ToInt32(ViewState[ROWINDEX].ToString());
                if (deleteRowIndex != -1 && deleteRowIndex < rowIndex)
                {
                    rowIndex--;
                }

                Label VisaId = (Label)gvVisaDetails.Rows[rowIndex].FindControl(VISAID);
                Label Mode   = (Label)gvVisaDetails.Rows[rowIndex].FindControl(MODE);

                gvVisaDetails.Rows[rowIndex].Cells[0].Text = txtCountryName.Text;
                gvVisaDetails.Rows[rowIndex].Cells[1].Text = txtVisaType.Text;
                gvVisaDetails.Rows[rowIndex].Cells[2].Text = ucDatePickerVisaExpiryDate.Text;

                if (int.Parse(VisaId.Text) == 0)
                {
                    Mode.Text = "1";
                }
                else
                {
                    Mode.Text = "2";
                }

                ImageButton btnImg = (ImageButton)gvVisaDetails.Rows[rowIndex].FindControl(IMGBTNDELETE);
                btnImg.Enabled            = true;
                ViewState[ROWINDEX]       = null;
                ViewState[DELETEROWINDEX] = null;
            }

            for (int i = 0; i < VisaDetailsCollection.Count; i++)
            {
                BusinessEntities.VisaDetails objVisaDetails = new BusinessEntities.VisaDetails();
                objVisaDetails = (BusinessEntities.VisaDetails)VisaDetailsCollection.Item(i);

                Label VisaId = (Label)gvVisaDetails.Rows[i].FindControl(VISAID);
                Label Mode   = (Label)gvVisaDetails.Rows[i].FindControl(MODE);

                objVisaDetails.VisaId = int.Parse(VisaId.Text);
                objVisaDetails.EMPId  = int.Parse(EMPId.Value);

                objVisaDetails.CountryName = gvVisaDetails.Rows[i].Cells[0].Text;
                objVisaDetails.VisaType    = gvVisaDetails.Rows[i].Cells[1].Text;
                objVisaDetails.ExpiryDate  = Convert.ToDateTime(gvVisaDetails.Rows[i].Cells[2].Text);
                objVisaDetails.Mode        = int.Parse(Mode.Text);
            }

            //Clear all the fields after inserting row into gridview
            this.ClearControls();

            btnAddRow.Visible    = true;
            btnUpdateRow.Visible = false;
            btnCancelRow.Visible = false;

            //Enabling all the edit buttons.
            for (int i = 0; i < gvVisaDetails.Rows.Count; i++)
            {
                ImageButton btnImgEdit = (ImageButton)gvVisaDetails.Rows[i].FindControl(IMGBTNEDIT);
                btnImgEdit.Enabled = true;
            }
            HfIsDataModified.Value = CommonConstants.YES;
        }
    }