将数据源和数据绑定属性添加到asp.net自定义控件 [英] Add datasource and databinding properties to an asp.net custom control

查看:103
本文介绍了将数据源和数据绑定属性添加到asp.net自定义控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用多选选项创建自定义控件。我想要的是一个下拉列表,其内容都有文本框,以启用多个选择。到目前为止我所做的是使用文本框和图像按钮显示为下拉列表。点击它后,将在下方打开一个面板,其中包含一个复选框列表。我想知道如何将数据绑定到此自定义控件,以便填充复选框列表



I am trying to create a custom control with multi select option. what i want is a dropdownlist whose contents all have text boxes to enable multiple selection. what i have done till now is i used a text box and image button to show as dropdownlist. And on clicking it, a panel will be opened below that will contain a checkbox list. i want to know how i can bind data to this custom control so that it will populate the checkbox list

[ToolboxData("<{0}:CustomDropdown  runat="server"></{0}:CustomDropdown>")]
   public class CustomDropdown : CompositeControl
   {
       TextBox textBox;
       ImageButton button;
       CheckBoxList checkBox;
       Panel pnlForChkBox;
       HtmlGenericControl div = new HtmlGenericControl("div");

       protected override void CreateChildControls()
       {
           Controls.Clear();

           textBox = new TextBox();
           textBox.ID = "txtbox";

           button = new ImageButton();
           button.ID = "btn";
           button.ImageUrl = "~/images/CustomDropdown.png";
           button.ImageAlign = ImageAlign.Middle;
           button.Click += new ImageClickEventHandler(button_Click);
           button.Height = Unit.Pixel(22);

           checkBox = new CheckBoxList();
           checkBox.ID = "chkList";


           pnlForChkBox = new Panel();
           pnlForChkBox.ID = "pnlForChkbox";
           pnlForChkBox.Controls.Add(checkBox);
           pnlForChkBox.Style.Add("border", "black 1px solid");
           pnlForChkBox.Style.Add("overflow-y", "scroll");
           pnlForChkBox.Style.Add("overflow-x", "x:hidden");
           pnlForChkBox.Style.Add("width", "180px");
           pnlForChkBox.Style.Add("Height", "180px");
           pnlForChkBox.Visible = false;
           this.Controls.Add(textBox);
           this.Controls.Add(button);
           this.Controls.Add(pnlForChkBox);

       }

推荐答案

CodePlex上将有一个带有复选框的自定义下拉控件使用源代码,您可以查看它并根据您的控件进行相应的更改,或者您可以直接使用它而不是构建您自己的控件...



http://dropdowncheckboxes.codeplex.com/ [ ^ ]







用于ASP.NET的DropDown和MultiselectDropDown控件 [ ^ ]
There will be a custom dropdown control with checkbox is available on CodePlex with source code, you can review it and make appropriate changes accordingly to your control, or you can use that directly instead of building your own control...

http://dropdowncheckboxes.codeplex.com/[^]

or

DropDown and MultiselectDropDown Controls for ASP.NET[^]


这篇关于将数据源和数据绑定属性添加到asp.net自定义控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆