private void createSegemnt(string SegmentType)
        {
            try
            {
                lblMainMsg.Text = string.Empty;
                AdvanceListMasterBase listMaster = new AdvanceListMasterBase(ConnectionString);
                AdvanceSegmentMasterBase segmentMaster = new AdvanceSegmentMasterBase(ConnectionString);
                AdvanceListContactMaster objListContactMaster = new AdvanceListContactMaster(ConnectionString);
                DataTable dtListContactMaster = new DataTable();
                dtListContactMaster.Columns.Add(new DataColumn("ListMasterID", typeof(string)));
                dtListContactMaster.Columns.Add(new DataColumn("ContactId", typeof(string)));
                dtListContactMaster.Columns.Add(new DataColumn("CreatedDate", typeof(string)));
                dtListContactMaster.Columns.Add(new DataColumn("ModifiedDate", typeof(string)));
                dtListContactMaster.Columns.Add(new DataColumn("IsSegment", typeof(bool)));
                dtListContactMaster.Columns.Add(new DataColumn("IsActive", typeof(bool)));
                List<string> contactids = new List<string>();
                contactids = (List<string>)Session["ContactId"];
                if (hdfListId.Value != "")
                {
                    bool isDeleted = objListContactMaster.DeleteAllContactsFromList(Convert.ToInt64(hdfListId.Value));
                    if (isDeleted)
                    {

                        foreach (string contactID in contactids)
                        {
                            DataRow rowListContactMaster = dtListContactMaster.NewRow();
                            rowListContactMaster["ListMasterID"] = hdfListId.Value;
                            rowListContactMaster["ContactId"] = contactID;
                            //rowListContactMaster["CreatedDate"] = DateTime.Now.ToString();
                            rowListContactMaster["ModifiedDate"] = DateTime.Now.ToString();
                            rowListContactMaster["IsActive"] = true;
                            dtListContactMaster.Rows.Add(rowListContactMaster);
                        }
                        string[] SourceColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                        string[] DestinationColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                        AdvanceListContactMaster.BulkCopy(dtListContactMaster, "AdvanceListContactMaster", SourceColumn, DestinationColumn, ConnectionString);

                        AdvanceListMasterPrimaryKey pk = new AdvanceListMasterPrimaryKey(Convert.ToInt64(hdfListId.Value));//hiddenEditID.Value));
                        AdvanceListMaster listMasterNew = AdvanceListMaster.SelectOne(pk, ConnectionString);

                        listMaster.ListMasterID = Convert.ToInt64(hdfListId.Value);
                        listMaster.ListName = txtSegmentName.Text;
                        listMaster.ListDesc = txtDescription.Text;
                        listMaster.CreatedDate = listMasterNew.CreatedDate;
                        listMaster.ModifiedDate = System.DateTime.Now;
                        listMaster.IsSegment = true;
                        listMaster.Update();

                        segmentMaster.ListMasterID = Convert.ToInt64(hdfListId.Value);
                        segmentMaster.SegmentName = txtSegmentName.Text;
                        segmentMaster.SelectCondition = SelectedIds.Value.Substring(0, SelectedIds.Value.Length);

                        if (rbSegCamRecOnly.Checked)
                            HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactField\" onChange='QueryBuild(this);'");
                        else
                            HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactField\" onChange='ListQueryBuild(this);'");
                        HtmlContent.Value = HtmlContent.Value.Replace("\"ddlOperatorName\"", "\"ddlOperator\" onChange='getSearchKeys(this);'");
                        HtmlContent.Value = HtmlContent.Value.Replace("\"ddlOperatorDefault\"", "\"ddlOperatorCommon\" onChange='displayDefaultValues(this);'");
                        segmentMaster.SegmentFilter = HtmlContent.Value;
                        segmentMaster.Type = SegmentType;
                        segmentMaster.Update();
                    }

                    Response.Redirect("~/pages/Segments.aspx?name=" + txtSegmentName.Text + "&mode=update");

                }
                else
                {

                    if (rgdContacts.MasterTableView.Items.Count > 0)
                    {
                        listMaster.ListName = txtSegmentName.Text;
                        listMaster.ListDesc = txtDescription.Text;
                        listMaster.CreatedDate = System.DateTime.Now;
                        listMaster.IsSegment = true;
                        listMaster.InsertWithDefaultValues(true);
                        Int64 listid = Convert.ToInt64(listMaster.ListMasterID);

                        segmentMaster.ListMasterID = listid;
                        segmentMaster.SegmentName = txtSegmentName.Text;
                        segmentMaster.SelectCondition = SelectedIds.Value.Substring(0, SelectedIds.Value.Length);
                        if (rbSegCamRecOnly.Checked)
                            HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactField\" onChange='QueryBuild(this);'");
                        else
                            HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactField\" onChange='ListQueryBuild(this);'");
                        HtmlContent.Value = HtmlContent.Value.Replace("\"ddlOperatorName\"", "\"ddlOperator\" onChange='getSearchKeys(this);'");
                        HtmlContent.Value = HtmlContent.Value.Replace("\"ddlOperatorDefault\"", "\"ddlOperatorCommon\" onChange='displayDefaultValues(this);'");
                        segmentMaster.SegmentFilter = HtmlContent.Value;
                        segmentMaster.Type = SegmentType;
                        segmentMaster.Insert();

                        foreach (string contactID in contactids)
                        {
                            DataRow rowListContactMaster = dtListContactMaster.NewRow();
                            rowListContactMaster["ListMasterID"] = listid;
                            rowListContactMaster["ContactId"] = contactID;
                            rowListContactMaster["CreatedDate"] = DateTime.Now.ToString();
                            rowListContactMaster["ModifiedDate"] = DateTime.Now.ToString();
                            rowListContactMaster["IsActive"] = true;
                            dtListContactMaster.Rows.Add(rowListContactMaster);
                        }
                        string[] SourceColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                        string[] DestinationColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                        AdvanceListContactMaster.BulkCopy(dtListContactMaster, "AdvanceListContactMaster", SourceColumn, DestinationColumn, ConnectionString);

                    }

                }
                Response.Redirect("~/pages/Segments.aspx?name=" + txtSegmentName.Text + "&mode=create");

            }
            catch (Exception ex)
            {

                lblMainMsg.Text = "Error: " + ex.Message;
                //lblMainMsg.Visible = true;
                rtsAddSegment.SelectedIndex = 0;
                rtsAddSegment.MultiPage.SelectedIndex = 0;

            }
        }
        /// <summary>
        /// Populates the fields of a single objects from the columns found in an open reader.
        /// </summary>
        /// <param name="obj" type="AdvanceSegmentMaster">Object of AdvanceSegmentMaster to populate</param>
        /// <param name="rdr" type="IDataReader">An object that implements the IDataReader interface</param>
        ///
        /// <remarks>
        ///
        /// <RevisionHistory>
        /// Author				Date			Description
        /// DLGenerator			12/29/2012 04:55:11 PM		Created function
        /// 
        /// </RevisionHistory>
        ///
        /// </remarks>
        ///
        internal static void PopulateObjectFromReader(AdvanceSegmentMasterBase obj,IDataReader rdr)
        {
            obj.ListMasterID = rdr.GetInt64(rdr.GetOrdinal(AdvanceSegmentMasterFields.ListMasterID));
            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceSegmentMasterFields.SegmentName)))
            {
                obj.SegmentName = rdr.GetString(rdr.GetOrdinal(AdvanceSegmentMasterFields.SegmentName));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceSegmentMasterFields.SelectCondition)))
            {
                obj.SelectCondition = rdr.GetString(rdr.GetOrdinal(AdvanceSegmentMasterFields.SelectCondition));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceSegmentMasterFields.SegmentFilter)))
            {
                obj.SegmentFilter = rdr.GetString(rdr.GetOrdinal(AdvanceSegmentMasterFields.SegmentFilter));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceSegmentMasterFields.Type)))
            {
                obj.Type = rdr.GetString(rdr.GetOrdinal(AdvanceSegmentMasterFields.Type));
            }
        }
        protected void lbtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                lblMainMsg.Text = string.Empty;
                listMaster = new AdvanceListMasterBase(ConnectionString);
                segmentMaster = new AdvanceSegmentMasterBase(ConnectionString);

                if (hdfListId.Value != "")
                {
                    AdvanceListMasters list = AdvanceListMaster.SelectByField("ListName", txtSegmentName.Text.Trim(), ConnectionString);

                    if (txtSegmentName.Text.Trim().Length <= 0)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Success", "alert('Please enter Segment Name .')", true);
                    }
                    else if (list.Count == 0)
                    {
                        updateSegmentDetails();
                    }
                    else if (list.Count > 0 && list[0].ListMasterID.ToString() == hdfListId.Value)
                    {
                        updateSegmentDetails();
                    }
                    else
                    {
                        //throw new Exception(string.Format("Segment: {0},  already exists. Please enter other name.", txtSegmentName.Text));
                        string listType = "";
                        listType = (list[0].IsSegment == true) ? "segments" : "list";
                        lblMainMsg.Text = "Segment:" + txtSegmentName.Text + ", already exists in " + listType + ". Please enter other name.";
                    }

                }

            }
            catch (Exception ex)
            {
                lblMainMsg.Text = ex.Message.ToString();
            }
        }