如何在dnn7中动态创建.ascx文件中的DNNDateTimePicker
本文关键字:ascx 文件 DNNDateTimePicker 创建 动态 dnn7 | 更新日期: 2023-09-27 18:17:19
我想为添加(即添加员工)功能创建动态表单。我可以创建所有的控件(TextBox, RadioButtonList, CheckBoxList, DropDownList),但我不知道如何创建DateTime控件。(
DNN提供现成的控件(http://uxguide.dotnetnuke.com/UIPatterns/DatePicker.html),但我不知道如何在我的代码中动态地创建它。
我也读过这个(http://www.ashishblog.com/assign-datepicker-to-runtimedynamic-textboxes-in-asp-net-using-jquery/),但它不工作
谁能建议我链接或方法来实现它?如果我可以使用DNNDateTime选择器会更好。
下面是我的代码:View.ascx<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="View.ascx.cs" Inherits="Customer.Modules.CustomerDemo.View" %>
<div id="div_customer" style="visibility: visible">
<asp:PlaceHolder ID="mainPlaceHolder" runat="server"></asp:PlaceHolder>
</div>
view . asx .cs ->页面加载事件
foreach (FieldsDetails item in listOfFields)
{
switch (item.FieldType)
{
case FieldTypes.Text:
TextBox textControl = new TextBox();
textControl.ID = "txt_" + item.FieldName;
textControl.Text = item.FieldValue;
textControl.TextChanged += TextControl_TextChanged; ;
mainPlaceHolder.Controls.Add(textControl);
break;
case FieldTypes.DropDown:
//code to create DropDown
break;
case FieldTypes.Checkbox:
//code to create Checkbox
break;
case FieldTypes.DateTime:
//code to create DateTime
//create TextBox control and apply class or Is there readyname DNN Control?
break;
}
}
您需要包含DotnetNuke。Web和Telerik.Web.UI组件在你的模块。
DnnDateTimePicker是Telerik RadDateTimePicker的包装。任何相关的文档都可以
var dtPicker1 = new DotNetNuke.Web.UI.WebControls.DnnDateTimePicker();
dtPicker1.ID = "dnnDatePicker1";
dtPicker1.Width = 300;
dtPicker1.Calendar.RangeMinDate = System.DateTime.Today;
dtPicker1.DateInput.EmptyMessage = "Select Date";
mainPlaceHolder.Controls.Add(dtPicker1);