日期:2014-05-17 浏览次数:20562 次
protected void Page_Load(object sender, EventArgs e) { foreach (ListItem cbox in cboxList.Items) { if (cbox.Selected) { Response.Write(cbox.Text+"选中了<br/>"); } } BindData(); } protected void BindData() { cboxList.DataSource = GetData(); cboxList.DataTextField = "Name"; cboxList.DataValueField = "Id"; cboxList.DataBind(); //随便设置选中几个,然后在设置字体为红色 foreach (ListItem cbox in cboxList.Items) { if (Convert.ToInt32(cbox.Value) % 2 == 0) { cbox.Attributes.Add("style", "color:red;"); } } } private DataTable GetData() { DataTable dt = new DataTable(); dt.Columns.Add("Id", typeof(int)); dt.Columns.Add("Name", typeof(string)); dt.Rows.Add(1, "2012-2-1"); dt.Rows.Add(2, "2012-2-2"); dt.Rows.Add(3, "2012-2-3"); dt.Rows.Add(4, "2012-2-4"); dt.Rows.Add(5, "2012-2-5"); dt.Rows.Add(6, "2012-2-1"); dt.Rows.Add(7, "2012-2-2"); dt.Rows.Add(8, "2012-2-2"); dt.Rows.Add(9, "2012-2-1"); return dt; }