列表框移动项目

时间:2012-02-08 19:15:04

标签: listbox

// Users
IEnumerable<String> selected_user_ids = from ListItem item in SelectedUsersListBox.Items select item.Value;
IEnumerable<RuleUser> existing_rule_users = dc.RuleUsers.Where(ru => ru.RuleID == ruleId && selected_user_ids.Contains(ru.MFAUserID.ToString()));
IEnumerable<String> existing_user_ids = existing_rule_users.Select(ru => ru.MFAUserID.ToString());
IEnumerable<RuleUser> delete_rule_users = dc.RuleUsers.Where(ru => ru.RuleID == ruleId).Except(existing_rule_users);
IEnumerable<String> new_user_ids = selected_user_ids.Except(existing_user_ids);
dc.RuleUsers.DeleteAllOnSubmit(delete_rule_users);
foreach (String userid in new_user_ids)
{
    RuleUser rule_user = new RuleUser();
    rule_user.MFAUserID = new Guid(userid);
    rule_user.RuleID = ruleId;
    dc.RuleUsers.InsertOnSubmit(rule_user);
}

protected void AddUserButton_Click(object sender, EventArgs e)
{
    ListItem item;
    while ((item = UnselectedUsersListBox.SelectedItem) != null)
    {
        SelectedUsersListBox.Items.Add(item);
        UnselectedUsersListBox.Items.Remove(item);
    }
}

protected void RemoveUserButton_Click(object sender, EventArgs e)
{
    ListItem item;
    while ((item = SelectedUsersListBox.SelectedItem) != null)
    {
        UnselectedUsersListBox.Items.Add(item);
        SelectedUsersListBox.Items.Remove(item);
    }
}

0 个答案:

没有答案