checkboxlist与数组结合用的技
生活随笔
收集整理的這篇文章主要介紹了
checkboxlist与数组结合用的技
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天看到一個checkboxlist與數組結合用的技巧。
????
??? 用戶自定義控件.ascx頁面有一個SqlDataSource數據源,還有一個Checkboxlist控件。下面來看看.cs里的關鍵代碼了:
? public string SelectedValue
??? {
??????? get
??????? {
??????????? string s = "";
??????????? for (int i = 0; i < CheckBoxList1.Items.Count; i++)
??????????? {
??????????????? if (CheckBoxList1.Items[i].Selected)
??????????????????? s += CheckBoxList1.Items[i].Value + ",";
??????????? }
??????????? return s;
??????? }
??????? set
??????? {
??????????? CheckBoxList1.DataBind();
??????????? string s = value;
??????????? string[] s_arr = s.Split(new char[] { ',' });//關鍵的部分哦
??????????? for (int i = 0; i < CheckBoxList1.Items.Count; i++)
??????????? {
??????????????? for (int j = 0; j < s_arr.Length - 1; j++)
??????????????? {
??????????????????? if (CheckBoxList1.Items[i].Value == s_arr[j])
??????????????????? {
??????????????????????? CheckBoxList1.Items[i].Selected = true;
??????????????????????? break;
??????????????????? }
??????????????? }
??????????? }
??????? }
用的時候,把Checkboxlist里的東西轉換成數組的時候的代碼:?
string[] act_arr = acts.SelectedValue.Split(new char[] { ',' });
????? 呵呵,很優美的一段代碼
????
??? 用戶自定義控件.ascx頁面有一個SqlDataSource數據源,還有一個Checkboxlist控件。下面來看看.cs里的關鍵代碼了:
? public string SelectedValue
??? {
??????? get
??????? {
??????????? string s = "";
??????????? for (int i = 0; i < CheckBoxList1.Items.Count; i++)
??????????? {
??????????????? if (CheckBoxList1.Items[i].Selected)
??????????????????? s += CheckBoxList1.Items[i].Value + ",";
??????????? }
??????????? return s;
??????? }
??????? set
??????? {
??????????? CheckBoxList1.DataBind();
??????????? string s = value;
??????????? string[] s_arr = s.Split(new char[] { ',' });//關鍵的部分哦
??????????? for (int i = 0; i < CheckBoxList1.Items.Count; i++)
??????????? {
??????????????? for (int j = 0; j < s_arr.Length - 1; j++)
??????????????? {
??????????????????? if (CheckBoxList1.Items[i].Value == s_arr[j])
??????????????????? {
??????????????????????? CheckBoxList1.Items[i].Selected = true;
??????????????????????? break;
??????????????????? }
??????????????? }
??????????? }
??????? }
用的時候,把Checkboxlist里的東西轉換成數組的時候的代碼:?
string[] act_arr = acts.SelectedValue.Split(new char[] { ',' });
????? 呵呵,很優美的一段代碼
轉載于:https://www.cnblogs.com/zhangliyu/archive/2009/06/14/1503253.html
總結
以上是生活随笔為你收集整理的checkboxlist与数组结合用的技的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网络编程基础(一)
- 下一篇: 关于spring boot多张表建立外健