Datepicker not appearing after adding rows to editable gridview

前端 未结 2 742
梦毁少年i
梦毁少年i 2021-01-20 21:40

I have an editable Gridview with columns as below:

    

        
相关标签:
2条回答
  • 2021-01-20 22:08

    $(function () {

            $('.DateTimePicker').datepick({ dateFormat: 'dd MM yyyy' });
        });
    

    It means it will hit once time. Try to use forEach function Like this:

    $(function () {
            $('.DateTimePicker').each(function () {
                $(this).datepick({ dateFormat: 'dd MM yyyy' });
             });
            //$('.DateTimePicker').datepick({ dateFormat: 'dd MM yyyy' });
        });
    
    0 讨论(0)
  • 2021-01-20 22:16

    The only case that this happens is when you use UpdatePanel.

    Now when you use UpdatePanel, on each UpdatePanel the Dom is change and the javascript need re-initializations. Now in your case you add new lines, and you make ajax update, so you need to re-initialize the date picker.

    This can be done from the functions that come with UpdatePanel as:

    <script type="text/javascript"> 
       // when dom is ready we initialize the UpdatePanel requests
       $(document).ready(function () {
           var prm = Sys.WebForms.PageRequestManager.getInstance();    
           prm.add_initializeRequest(InitializeRequest);
           prm.add_endRequest(EndRequest);
    
           // Place here the first init of the DatePicker           
           $('.DateTimePicker').datepick({ dateFormat: 'dd MM yyyy' });
        });        
    
        function InitializeRequest(sender, args) {
           // make unbind before update the dom, to avoid memory leaks.
           $('.DateTimePicker').unbind();
        }
    
        function EndRequest(sender, args) {
           // after update occur on UpdatePanel re-init the DatePicker
           $('.DateTimePicker').datepick({ dateFormat: 'dd MM yyyy' });
        }
    </script>
    

    Similar: Asp.Net UpdatePanel in Gridview Jquery DatePicker
    Datepicker for dynamically created controls

    0 讨论(0)
提交回复
热议问题