private int CreatePayableMapping()
        {
            StringBuilder sbAgentid = new StringBuilder();
            StringBuilder sbRuleid  = new StringBuilder();
            string        ruleId    = string.Empty;

            try
            {
                foreach (GridDataItem gdi in rgPayableMapping.MasterTableView.Items)
                {
                    CheckBoxList chkListrate = (CheckBoxList)gdi.FindControl("chkListrate");
                    for (int i = 0; i < chkListrate.Items.Count; i++)
                    {
                        if (chkListrate.Items[i].Selected)
                        {
                            //Storing the selected values
                            ruleId = ruleId + "," + chkListrate.Items[i].Value;
                        }
                    }
                }
                if (ruleId != "")
                {
                    ruleId = ruleId.Trim(',');
                    DataTable dtRuleMapping = new DataTable();
                    dtRuleMapping.Columns.Add("agentId", typeof(string));
                    dtRuleMapping.Columns.Add("ruleids");

                    DataRow drRuleMapping;
                    int     mappingId  = 0;
                    string  agentId    = string.Empty;
                    string  categoryId = string.Empty;
                    if (ddlType.SelectedValue == "Custom")
                    {
                        foreach (RadListBoxItem ListItem in this.RadListBoxSelectedAgentCodes.Items)
                        {
                            agentId = ListItem.Value;
                            sbAgentid.Append(ListItem.Value);
                            foreach (object rule in ruleId.Split(','))
                            {
                                drRuleMapping            = dtRuleMapping.NewRow();
                                drRuleMapping["agentId"] = agentId;
                                drRuleMapping["ruleids"] = rule;
                                dtRuleMapping.Rows.Add(drRuleMapping);
                            }
                        }
                    }
                    else
                    {
                        categoryId = ddlAdviserCategory.SelectedValue;
                    }

                    commisionReceivableBo.CreateAdviserPayableRuleToAgentCategoryMapping(Convert.ToInt32(hdnStructId.Value), ddlMapping.SelectedValue, categoryId, dtRuleMapping, ruleId.TrimEnd(','), 0, out mappingId);
                    return(mappingId);
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "alert('Please select rate(%)');", true);
                    return(0);
                }
            }
            catch (BaseApplicationException Ex)
            {
                throw Ex;
            }
            catch (Exception Ex)
            {
                string filePath             = WebConfigurationManager.AppSettings["filePath"];
                System.IO.StreamWriter file = new System.IO.StreamWriter(filePath + "\\log.txt");
                file.WriteLine("RuleId" + ruleId + "::" + "AgentId" + sbAgentid);
                file.WriteLine();
                file.Close();
                BaseApplicationException exBase       = new BaseApplicationException(Ex.Message, Ex);
                NameValueCollection      FunctionInfo = new NameValueCollection();
                FunctionInfo.Add("Method", "CommissionStructureToSchemeMapping.ascx.cs:CreatePayableMapping()");
                exBase.AdditionalInformation = FunctionInfo;
                ExceptionManager.Publish(exBase);
                throw exBase;
            }
        }