miniui中checkboxlist如何添加选中事件
1个回答
展开全部
string stra1 = "";
string stra2 = "";
string strb1 = "";
string strb2 = "";
//获取第一个checkboxlist的所有选中item的value和text
if (tutornam.Items.Count != 0) {
foreach (ListItem li2 in tutornam.Items) {
if (li2.Selected == true) {
stra1 += li2.Value + ",";
stra2 += li2.Text.Trim + ",";
}
}
}
//获取第二个checkboxlist的所有选中item的value和text
foreach (ListItem li in CheckBoxTutornam.Items) {
if (li.Selected == true) {
strb1 += li.Value + ",";
strb2 += li.Text.Trim + ",";
}
}
//把获取到的值转换成数组
string[] arry1 = stra1.Split(",");
string[] arry2 = stra2.Split(",");
string[] arry3 = strb1.Split(",");
string[] arry4 = strb2.Split(",");
int i = 0;
int j = 0;
int a = arry1.Length;
int b = arry3.Length;
//拿数组arry3的每个值与arry1 的每个值比较,如果arry1(i) != arry3(j)就添加该item到另外一个checkboxlist
for (j = 0; j <= b - 1; j++) {
for (i = 0; i <= a - 1; i++) {
if (arry1(i) != arry3(j)) {
tutornam.Items.Add(new ListItem(arry4(j), arry3(j)));
tutornam.Items(tutornam.Items.Count - 1).Selected = true;
}
string stra2 = "";
string strb1 = "";
string strb2 = "";
//获取第一个checkboxlist的所有选中item的value和text
if (tutornam.Items.Count != 0) {
foreach (ListItem li2 in tutornam.Items) {
if (li2.Selected == true) {
stra1 += li2.Value + ",";
stra2 += li2.Text.Trim + ",";
}
}
}
//获取第二个checkboxlist的所有选中item的value和text
foreach (ListItem li in CheckBoxTutornam.Items) {
if (li.Selected == true) {
strb1 += li.Value + ",";
strb2 += li.Text.Trim + ",";
}
}
//把获取到的值转换成数组
string[] arry1 = stra1.Split(",");
string[] arry2 = stra2.Split(",");
string[] arry3 = strb1.Split(",");
string[] arry4 = strb2.Split(",");
int i = 0;
int j = 0;
int a = arry1.Length;
int b = arry3.Length;
//拿数组arry3的每个值与arry1 的每个值比较,如果arry1(i) != arry3(j)就添加该item到另外一个checkboxlist
for (j = 0; j <= b - 1; j++) {
for (i = 0; i <= a - 1; i++) {
if (arry1(i) != arry3(j)) {
tutornam.Items.Add(new ListItem(arry4(j), arry3(j)));
tutornam.Items(tutornam.Items.Count - 1).Selected = true;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询