Tag: asp.net controls

带有附加可绑定字段的ASP.NET Server控件

我创建了一个自定义服务器控件,派生自System.Web.Contols.CheckBoxList来自定义CheckBoxList的呈现方式。 我还想添加另一个可绑定字段,并在CheckBoxList.RenderItem()方法中获取该字段的值。 我想要创建的字段应包含一个值,指定是否选中CheckBoxListItem 。 我已经阅读了一些关于自定义DataFields的文章,但它从未得到详细解释。 我已经把我课程的一部分包括在内,以便更好地解释我似乎无法理解的内容。 public class ListedCheckBoxList : CheckBoxList { protected override void RenderItem(ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer) { if (itemType != ListItemType.Item) return; var item = base.Items[repeatIndex]; string cbxHtml = string.Format(” {2}”, item.Value, string.Concat(this.ClientID, repeatIndex), item.IsChecked, // <– My custom bindable field item.Text); writer.Write(cbxHtml); } } 在.aspx页面中使用此控件时,我试图像这样绑定它

如何创建基于属性显示页眉,页脚的自定义中继器?

我想创建一个基于属性显示页眉/页脚的Repeater,仅当DataSource为空时才显示。 public class Repeater : System.Web.UI.WebControls.Repeater { public bool ShowHeaderOnEmpty { get; set; } public bool ShowFooterOnEmpty { get; set; } [DefaultValue((string)null), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(System.Web.UI.WebControls.RepeaterItem)), Browsable(false)] public ITemplate EmptyTemplate { get; set; } } 我还想创建一个EmptyTemplate ,如果DataSource为空则显示此模板… 我不知道如何实现这一点。 我应该覆盖什么来实现这种行为?

如何禁用ASP.NET页面中的所有控件?

我在页面中有多个下拉列表,并且如果用户选择一个禁用全部的复选框,则要禁用所有。 到目前为止,我有这个代码,它无法正常工作。 有什么建议? foreach (Control c in this.Page.Controls) { if (c is DropDownList) ((DropDownList)(c)).Enabled = false; }