asp.netメモ

asp.netメモ

//drop down list
Dictionary<string,string> dic = new Dictionary<string,string>();
dic.Add("日曜日", "0");
dic.Add("月曜日", "1");
dic.Add("火曜日", "2");
this.CreateDropDownList(this.rabTest, dic);


private void CreateDropDownList(RadioButtonList rbList, Dictionary<string,string> dic) 
{
    DataTable dt = new DataTable();
    dt.Columns.Add("Text", typeof(string));
    dt.Columns.Add("Value", typeof(string));

    foreach (string key in dic.Keys)
    {
        dt.Rows.Add(key, dic[key]);
    }

    rbList.DataSource = dt;
    rbList.DataTextField = "Text";
    rbList.DataValueField = "Value";
    rbList.DataBind();
}
// check box list
DataTable dt3 = new DataTable();
dt3.Columns.Add("Text", typeof(string));
dt3.Columns.Add("Value", typeof(int));
dt3.Rows.Add("日曜日", 0);
dt3.Rows.Add("月曜日", 1);
dt3.Rows.Add("火曜日", 2);
this.cblTest.DataSource = dt3;
this.cblTest.DataTextField = "Text";
this.cblTest.DataValueField = "Value";
this.cblTest.DataBind();
this.cblTest.Items[1].Selected = true;

private List<string> GetCheckedCheckBoxList(CheckBoxList cb) 
{
    List<string> resultList = new List<string>();

    foreach (ListItem item in cb.Items)
   {
        if (item.Selected)
       {
            resultList.Add(item.Value);
       }
   }

    return resultList;
}