Nanji Mange Nanji Mange - 24 days ago 6
ASP.NET (C#) Question

How to create datetimepicker dynamically(without class) in asp.net with C#?

I want to create

DateTimePicker
dynamically. I have reviewed few reference but all suggest to create class and assign it to
TextBox
control which has created dynamically(http://www.ashishblog.com/assign-datepicker-to-runtimedynamic-textboxes-in-asp-net-using-jquery/). I want to create
DateTimePicker
dynamically in .cs file without support of any class.

i.e Text Control

TextBox textControl = new TextBox();
textControl.ID = "txt_ID";
textControl.Text = "";
textControl.AutoPostBack = true;
textControl.TextChanged += TextControl_TextChanged; ;
mainPlaceHolder.Controls.Add(textControl);


Can anybody please suggest me link or lines of code?

Answer

First install or download manually and paste it in your codebase

nuget

Install-Package Bootstrap.Datepicker

then follow along

 <link href="Content/bootstrap.min.css" rel="stylesheet" />
    <link href="Content/bootstrap-datepicker.css" rel="stylesheet" />
    <script src="Scripts/jquery-1.10.2.js"></script>
    <script src="Scripts/bootstrap.js"></script>
    <script src="Scripts/bootstrap-datepicker.min.js"></script>
    <div id="add">
        <input type="text" name="datepicker " value=" " class="form-control mytimepicker" />
        <button id="addMore">addMore</button>
    </div>
    <script>
        $(function () {
            $(document).on('focus', '.mytimepicker', function (e) {
                $(this).datepicker({
                    autoclose: 'true'
                });
            });

            $('#addMore').click(function (e) {
                e.preventDefault();
                $('#add').append('<input type="text" name="datepicker " value=" " class="form-control mytimepicker" />');
            });
        });
    </script>

more info about datepicker bootstrap-datepicker

Comments