zoukankan      html  css  js  c++  java
  • 为CheckBoxList每个项目添加一张图片

    参考下图,可看到效果,为CheckBoxList每个项目添加一张图片。

    准备五张图片,如上图,和CheckBoxList项目数据:

    View Code
    private Dictionary<stringstring> Operation()
        {
            Dictionary<stringstring> o = new Dictionary<stringstring>();
            o.Add("i","Insert");
            o.Add("e","Edit");
            o.Add("c","Cancel");
            o.Add("u","Update");
            o.Add("d","Delete");
            return o;
        }

    然后在.aspx,并使用OnDataBound事件:

     <asp:CheckBoxList ID="CheckBoxListOperation" runat="server" RepeatColumns="1" RepeatDirection="Horizontal" OnDataBound="CheckBoxListOperation_DataBound">
                </asp:CheckBoxList>

    .aspx.cs:

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

        private void Data_Binding()
        {
            this.CheckBoxListOperation.DataSource = Operation();
            this.CheckBoxListOperation.DataTextField = "value";
            this.CheckBoxListOperation.DataValueField = "key";
            this.CheckBoxListOperation.DataBind();
        }

    OnDataBound="CheckBoxListOperation_DataBound"事件:

    View Code
    protected void CheckBoxListOperation_DataBound(object sender, EventArgs e)
        {
            var cbl = sender as CheckBoxList;
            foreach (ListItem li in cbl.Items)
            {
                li.Text = string.Format("<img src='Images/{0}.gif' /> {1}", li.Value, li.Text);
            }
        }
  • 相关阅读:
    C# XmlSerializer实现序列化浅析(转载)
    Direct3D学习(资料收集)
    幸福法则
    javascript中的keydown事件中的参数问题
    去除UTF8 BOM【转】
    JavaScript常用资料参考
    KCFinder CKEditor的文件管理器插件
    elFinder Web文件管理器
    用TcpTrace调试Web服务器
    Ubuntu 12.04如何登入root?
  • 原文地址:https://www.cnblogs.com/insus/p/2418874.html
Copyright © 2011-2022 走看看