当前位置: 代码迷 >> ASP.NET >> 点击确定旋钮获取checkboxlist选中值 但是页面刷新了 没有选中项了
  详细解决方案

点击确定旋钮获取checkboxlist选中值 但是页面刷新了 没有选中项了

热度:3590   发布时间:2013-02-25 00:00:00.0
点击确定按钮获取checkboxlist选中值 但是页面刷新了 没有选中项了
如何在不实用 !isPostBack的情况下实现呢??????

------解决方案--------------------------------------------------------
C# code
    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;    }