mardi 30 avril 2019

Gridvew Looping for multiple times even when selected least records in asp.net

I have a gridview in which every row contains a checkbox for selection. That selection will be used for Approve or Reject purpose.

But issue here is If I select 2 rows from the gridview it loops atleast 4-5 times and gives me multiple emails of the same row.

Below is my code. Please suggest.

if (ViewState["CheckedCheckboxes_CMM"] != null)
            {
                var CheckedCheckboxes_CMM = (List<int>)ViewState["CheckedCheckboxes_CMM"];

                foreach (var id in CheckedCheckboxes_CMM)
                {
                    flgCMM = true;

                    int Id = id;

                    foreach (GridViewRow row in grdDisplayCMMData.Rows)
                    {
                        Label SAPID_CMM = (Label)row.FindControl("lblSAP_ID_CMM");

                        ObjIPColoFields.Unique_Id = Id;
                        ObjIPColoFields.UMS_GRP_BY_ID = intCurrentGrpId;
                        ObjIPColoFields.UMS_GRP_BY_NAME = strCurrentGrp;
                        ObjIPColoFields.UMS_GRP_TO_ID = UMSGroupDetails[1].GroupID;
                        ObjIPColoFields.UMS_GRP_TO_NAME = UMSGroupDetails[1].GroupName;
                        ObjIPColoFields.FCA_STATUS = "1";
                        ObjIPColoFields.LAST_UPDATED_BY = lblUserName.Text;
                        strDate = DateTime.Now.ToString();                                                    

                        strApprove = CommonDB.Approve_IPCOLO_CMMLevel(ObjIPColoFields);

                        if (ObjIPColoFields.Unique_Id != null || ObjIPColoFields.Unique_Id != 0)
                        {
                            strMailContent = Get_Email_Content(ObjIPColoFields.LAST_UPDATED_BY, SAPID_CMM.Text, strIPCOLO_CMM, Convert.ToString(Id), strDate, "Approved");
                            SendEmail(lblUserName.Text, strMailContent, strIPCOLO_CMM);
                        }
                    }
                }

            }

Aucun commentaire:

Enregistrer un commentaire