0

I want to create Dynamic Form for Add (i.e Add Employee) functionality. I can create all the control(TextBox, RadioButtonList, CheckBoxList, DropDownList) but I don't know how to create DateTime control. :(

DNN Provides readymade control(http://uxguide.dotnetnuke.com/UIPatterns/DatePicker.html) but I don't know how to create it dynamically in my code.

I have read this(http://www.ashishblog.com/assign-datepicker-to-runtimedynamic-textboxes-in-asp-net-using-jquery/) also but it doesn't work

Can anybody suggest me link or way to achieve it? It would be better it I can use DNNDateTime picker.

Here is my code: 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 --> Page Load event

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;
    }
}
Nanji Mange
  • 2,155
  • 4
  • 29
  • 63

1 Answers1

0

You need to include DotnetNuke.Web and Telerik.Web.UI assemblies in your module.

The DnnDateTimePicker is a wrapper around the Telerik RadDateTimePicker. So any documentation you find for that is applicable

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);
Fix It Scotty
  • 2,852
  • 11
  • 12