我在更新面板中有网格视图,在网格视图中有多行文本框,我已经安排了代码,当我点击链接时按钮,网格视图的行将增加,但问题是,当我想将jquery datepicker应用于txtDate文本框时,它适用于第一行文本框,但当我在网格视图中的行增加时单击链接按钮时,日期选择器功能不起作用.... 我的代码是..
<script type="text/javascript">
$(document).ready(function () {
$("[id$=txtDate]").datepicker();
});
</script>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/Scripts/jquery-2.0.3.js" />
<asp:ScriptReference Path="~/Scripts/jquery-ui-1.10.3.js" />
</Scripts>
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:gridview ID="Gridview1" runat="server" ShowFooter="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
<asp:TemplateField HeaderText="First Name">
<ItemTemplate>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name">
<ItemTemplate>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:TextBox ID="txtDate" runat="server" AutoPostBack="true">
</asp:TextBox>
</ItemTemplate></asp:TemplateField>
</Columns>
</asp:gridview>
<asp:LinkButton ID="lnkMore" runat="server" Text="More(>>)" OnClick="lnkMore_Click"></asp:LinkButton>
<asp:LinkButton ID="lnkLess" runat="server" Text="Less(<<)" OnClick="lnkLess_Click"></asp:LinkButton>
</ContentTemplate></asp:UpdatePanel>
请帮帮我..
答案 0 :(得分:4)
这是解决方案..
<script type="text/javascript">
$(function () {
$('.date').datepicker();
});
</script>
<asp:ScriptManager ID="scm1" runat="server">
</asp:ScriptManager>
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(getme);
function getme() {
$('.date').datepicker();
}
</script>
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<asp:gridview ID="Gridview1" runat="server" ShowFooter="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" >
<Columns>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:TextBox ID="txtDate" runat="server" class="date" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</ContentTemplate></asp:UpdatePanel>
答案 1 :(得分:1)
我喜欢这个问题。它是更新面板的问题。 只需添加以下代码即可。
</asp:ScriptManager>
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(getme);
function getme() {
$("[id$=txtDate]").datepicker();
}
</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
我希望这能解决你的问题。否则请回复。
答案 2 :(得分:0)
使用类选择器而不是ID选择器,因为ID必须是UNIQUE元素。
看起来像是:
<script type="text/javascript">
$(document).ready(function () {
$(".datepick").datepicker();
});
</script>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/Scripts/jquery-2.0.3.js" />
<asp:ScriptReference Path="~/Scripts/jquery-ui-1.10.3.js" />
</Scripts>
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:gridview ID="Gridview1" runat="server" ShowFooter="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
<asp:TemplateField HeaderText="First Name">
<ItemTemplate>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name">
<ItemTemplate>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:TextBox ID="txtDate" class='datepick' runat="server" AutoPostBack="true">
</asp:TextBox>
</ItemTemplate></asp:TemplateField>
</Columns>
</asp:gridview>
<asp:LinkButton ID="lnkMore" runat="server" Text="More(>>)" OnClick="lnkMore_Click"></asp:LinkButton>
<asp:LinkButton ID="lnkLess" runat="server" Text="Less(<<)" OnClick="lnkLess_Click"></asp:LinkButton>
</ContentTemplate></asp:UpdatePanel>
请注意<asp:TextBox ID="txtDate" class='datepick' runat="server" AutoPostBack="true">
修改强>
因为您必须将与文本字段other topic from this issue
一样多的日期选择器实例化$(document).ready(function () {
$(".datepick").each(function() {
$(this).datepicker();
});
});