• 为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);
            }
        }
  • 相关阅读:
    5.MFC基础(五)视图、运行时类信息、动态创建
    4.MFC基础(四)菜单、工具栏、状态栏
    OpenCV Python 4.0安装
    windows批量导出文件名到txt
    *&p理解
    VS调试快捷键配置更改
    数组类的创建(下)
    数组类的创建(上)
    operator用法:隐式类型转换
    C++单例模式
  • 原文地址:https://www.cnblogs.com/insus/p/2418874.html
Copyright © 2020-2023  润新知