Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

Asp.Net UpdatePanel in Gridview Jquery DatePicker

<asp:UpdatePanel ID="asd" runat="server">
    <ContentTemplate>
    <asp:GridView ID="gvUpdate" runat="server">
    <Columns>
    <asp:TemplateField HeaderText="DATE">
    <ItemTemplate>
    <asp:Label ID="lblDate" runat="server" Text='<%# Eval("DATE","{0:dd.MM.yyyy}")%>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtDate" runat="server" Text='<%# Eval("DATE","{0:dd.MM.yyyy}") %>'></asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateField>
    </Columns>
    </ContentTemplate>

i want jquery datepicker for "txtDate" how to make ?

Thank you...

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The most simple way is to place a class on your Date Text box, and just use jQuery to add the datepicker...

<EditItemTemplate>
<asp:TextBox ID="txtDate" CssClass="clDate" 
  runat="server" Text='<%# Eval("DATE","{0:dd.MM.yyyy}") %>'></asp:TextBox>
</EditItemTemplate>

and the javascript for init this is: $(".clDate").datepicker(); but the update panel is need again initialization after the Update, so the final code will be:

<script type="text/javascript"> 
   // if you use jQuery, you can load them when dom is read.
   $(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
       $(".clDate").datepicker();
    });        

    function InitializeRequest(sender, args) {
       // make unbind to avoid memory leaks.
       $(".clDate").unbind();
    }

    function EndRequest(sender, args) {
       // after update occur on UpdatePanel re-init the DatePicker
       $(".clDate").datepicker();
    }
</script> 

Update:About the Sys. -> http://msdn.microsoft.com/en-us/library/bb311028.aspx


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...