栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

高亮CheckBoxList选中的项目

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

高亮CheckBoxList选中的项目


 

准备数据:

http://www.cnblogs.com/insus/articles/1439030.html

 

.aspx:

            onDataBound="CheckBoxListColour_DataBound" onSelectedIndexChanged="CheckBoxListColour_SelectedIndexChanged"
            AutoPostBack="true">
        

 

从上面的数据,下载并放入asp.net专案中,然后读出所有图片文件:

View Code  private List ImageNames
    {
        get
        {
            List o = new List();

            DirectoryInfo di = new DirectoryInfo(Server.MapPath ("~/Colours"));
            FileInfo[] fiArray = di.GetFiles();
            for (int i = 0; i < fiArray.Length; i++)
            {
                o.Add(fiArray[i].Name);
            }
            return o;
        }
    }

 

绑定数据至CheckBoxList控件:

View Code  protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Data_Binding();
        }
    }

    private void Data_Binding()
    {
        this.CheckBoxListColour.DataSource = ImageNames.Select(c => new { value = c }).ToList();
        this.CheckBoxListColour.DataTextField = "value";
        this.CheckBoxListColour.DataBind();
    }

 

 CheckBoxList控件的OnDataBound="CheckBoxListColour_DataBound"事件。

View Code  protected void CheckBoxListColour_DataBound(object sender, EventArgs e)
    {
        var cbl = sender as CheckBoxList;
        foreach (ListItem li in cbl.Items)
        {
            li.Text = string.Format("", li.Value);
        }
    }

 

CheckBoxList控件的OnSelectedIndexChanged="CheckBoxListColour_SelectedIndexChanged"事件。

View Code protected void CheckBoxListColour_SelectedIndexChanged(object sender, EventArgs e)
    {
        var cbl = sender as CheckBoxList;
        foreach (ListItem li in cbl.Items)
        {
            if (li.Selected)
            {
                li.Attributes.Add("style", "background-color: red;");
            }
        }
    }

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/246980.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号