首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-06-20 
点击确定按钮获取checkboxlist选中值 但是页面刷新了 没有选中项了如何在不实用 !isPostBack的情况下实现

点击确定按钮获取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;    } 

热点排行