I have a Checkbox list in my page and its datasource set programatically in PreLoad() event:
protected void Page_PreLoad()
{
if (!Page.IsPostBack)
{
CheckBoxList1.DataSource = NoK.AcceptedNoks((Guid)Membership.GetUser().ProviderUserKey);
CheckBoxList1.DataTextField = "FullName";
CheckBoxList1.DataValueField = "NoKId";
CheckBoxList1.DataBind();
}
foreach (ListItem chk in CheckBoxList1.Items)
{
if (PrivateMessage.HasAccess(Request.QueryString["MessageId"], chk.Value))
{
chk.Selected = true;
}
}
}
as you see in foreach will check for whether an item must be checked or Not. and it works nice. this means that end-user can Edit list Items and by default some of Item has been checked. now I want to get items by clicking a Button:
protected void UpdateRightBtn_Click(object sender, EventArgs e)
{
var SelectedNokIds =
CheckBoxList1.Items
.OfType<ListItem>()
.Where(li =>
li.Selected == true)
.Select(l => new Guid(l.Value));
}
but the Items in SelectedNokIds
are still Old Items and if user change checkboxes no effect apeares in SelectedNokIds
. Why???
Please Help!