开发者

Checkboxes changed state? How to find out which checkboxes have changed their state

开发者 https://www.devze.com 2023-03-17 09:25 出处:网络
using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Repeater_Checkbox
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            repeater.DataSource = PopulateCollection();
            repeater.DataBind();
        }

        public CollectionProfiles PopulateCollection()
        {
            var lista = new CollectionProfiles();

            var p1 = new Profile {ProfileDesc = "asdas", ProfileID = 1, ProfileStatus = 1};
            lista.Add(p1);

            var p2 = new Profile {ProfileDesc = "asdasd", ProfileID = 2, ProfileStatus = 0};
            lista.Add(p2);

            var p3 = new Profile {ProfileDesc = "nsadsdot", ProfileID = 3, ProfileStatus = 1};
            lista.Add(p3);

            var p4 = new Profile {ProfileDesc = "gluposti", ProfileID = 4, ProfileStatus = 1};
            lista.Add(p4);

            var p5 = new Profile {ProfileDesc = "asdaile", ProfileID = 5, ProfileStatus = 0};
            lista.Add(p5);

            var p6 = new Profile {ProfileDesc = "sdfsdf", ProfileID = 6, ProfileStatus = 1};
            lista.Add(p6);

            var p7 = new Profile {ProfileDesc = "dfsdf", ProfileID = 7, ProfileStatus = 1};
            lista.Add(p7);

            return lista;
        }

        protected void repeater_ItemDataBound(object source, RepeaterItemEventArgs e)
        {
            var taaLista = PopulateCollection();
            var someItem = (CheckBox)e.Item.FindControl("checkbox");
            var profileID = Convert.ToInt32(someItem.Attributes["data-id"]);

            foreach (var item in taaLista)
            {
                if ((item.ProfileID == profileID) && (item.ProfileStatus == 1))
                {
                    someItem.Checked = true;
                    return;
                }
                someItem.Checked = false;
            }
        }

        public class CollectionProfiles :开发者_StackOverflow中文版 Collection<Profile>
        {

        }
}

So far so good. I'm handling the OnItemDataBound event to check those textboxes that show profiles with the property Profile.StatusID set to 1.

Now i want to capture all changes. Say if a user unchecks a checkbox or checkes a previously unchecked checkbox I'd like to save the ID's of those Profiles in a list. How do I proceed.

Thanks in advance. I'd appreciate even if you give me ideas to revolve around. Thanks again!


You need to handle the Checkbox changed event after this you can determine if it is your collection or not and add or remove it accordingly

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号