My code:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:GridView runat="server" ID="MyGridView" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Col1" HeaderText="Column 1" />
<asp:BoundField DataField="Col2" HeaderText="Date 1" />
<asp:BoundField DataField="Col3" HeaderText="Date 2" />
<asp:TemplateField HeaderText="Date 2" >
<EditItemTemplate>
<asp:TextBox ID="txtDate" CssClass="datepickerCompleted"
runat="server" Text="2011/1/1" ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Col4" HeaderText="Date 3" />
<asp:TemplateField HeaderText="Date 3"></asp:TemplateField>
</Columns>
</asp:GridView>
<script type="text/javascript" language="javascript" src="<%= VirtualPathUtility.ToAbsolute("~/Script/jquery-1.4.1-vsdoc.js")%>"></script>
<script type="text/javascript">
$(function () {
$(".datepickerC开发者_如何学Pythonompleted").datepicker();
});
</script>
</asp:Content>
Followed example from here: enter link description here
When I look at the source, i do not see any value populate in txtDate text box, which i suspect is then not firing the jquery method..
how do i debug?
Your code looks good, but the datepicker
is part of jQuery UI which is a separate download/script--it's not included in the jquery-1.4.1 file, and it looks like that's the only script you have referenced.
EDIT: Here's an example that works for me:
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui-1.8.12.custom.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$(".datepickerCompleted").datepicker();
});
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:GridView runat="server" ID="MyGridView" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Date 2">
<ItemTemplate>
<asp:TextBox ID="txtDate" CssClass="datepickerCompleted" runat="server" Text="2011/1/1" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Content>
You can download a copy of jQuery UI here, and here's some more information on the datapicker
.
Based on the active/voted Answer, I think one more statement shall be added for better visibility of the datepicker. Otherwise it would be blurred/dimmed by the background. The proposed statement is put at 2nd line (assuming jquery-ui-1.8.14.custom.css file is downloaded & put in Css folder):
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<link type="text/css" href="Css/jquery-ui-1.8.14.custom.css" rel="Stylesheet" />
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui-1.8.12.custom.min.js" type="text/javascript"></script>
...
精彩评论