2016-11-11 33 views
0

我想爲添加(即添加員工)功能創建動態表單。我可以創建所有的控件(TextBox,RadioButtonList,CheckBoxList,DropDownList),但我不知道如何創建DateTime控件。 :(如何在DNN 7中動態創建.ascx文件中的DNNDateTimePicker?

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.ascx.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; 
    } 
} 

回答

0

您需要包括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);