0
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 : Collection<Profile>
{
}
}
到目前为止好。我处理OnItemDataBound事件,以检查那些显示轮廓与物业Profile.StatusID设置为1复选框已更改状态?如何找出哪些复选框已经改变了他们的状态
现在我想捕获所有的变化文本框。说,如果用户取消选中复选框或checkes先前未选中的复选框我想保存这些个人资料的ID在列表中。我如何继续。
在此先感谢。即使你给我一些想法,我也会很感激。再次感谢!
是啊,我知道这种情况的存在,但我可以使用它没有立即回张贴?例如,我可以为该事件设置事件处理程序,并且只有在用户单击该按钮时才会触发该事件? – Dragan