Exemplo n.º 1
0
    protected void btnaddmember_Click(object sender, EventArgs e)
    {
        List <string> memberNoList = new List <string>();

        if (txtphno.Text != "")
        {
            if (txtphno.Text == Request.Cookies["Phone_no"].Value.ToString())
            {
                ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('Add members number excluding you.')", true);
                return;
            }
            if (Session["ListOfNumbers"] != null)
            {
                string stringOfNumbers = Session["ListOfNumbers"].ToString();
                memberNoList = stringOfNumbers.Split(',').ToList <string>();
            }
            int pos = memberNoList.IndexOf(txtphno.Text.Trim());
            if (pos >= 0)
            {
                ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('Number already added')", true);
                return;
            }

            memberNoList.Add(txtphno.Text.Trim());
            RepeaterMemberList.DataSource = from c in memberNoList select new { newMemberPhoneNo = c };
            RepeaterMemberList.DataBind();
            Session["ListOfNumbers"] = string.Join(",", memberNoList);
            Session.Timeout          = 30;
            txtphno.Text             = "";
            txtphno.Focus();
        }
    }
Exemplo n.º 2
0
    protected void RepeaterMemberList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "cross")
        {
            if (Session["ListOfNumbers"] != null)
            {
                List <string> memberNoList = new List <string>();
                int           repeterIndex = e.Item.ItemIndex;

                string stringOfNumbers = Session["ListOfNumbers"].ToString();
                memberNoList = stringOfNumbers.Split(',').ToList <string>();

                if (memberNoList.Count == 1)
                {
                    memberNoList.Clear();
                    RepeaterMemberList.DataSource = null;
                    RepeaterMemberList.DataBind();
                    Session["ListOfNumbers"] = null;
                }
                else
                {
                    memberNoList.RemoveAt(repeterIndex);
                    RepeaterMemberList.DataSource = from i in memberNoList select new { newMemberPhoneNo = i };
                    RepeaterMemberList.DataBind();
                    Session["ListOfNumbers"] = string.Join(",", memberNoList);
                }
                Session.Timeout = 30;
            }
        }
    }