如何使用jQuery datepicker作为SqlDataSource的控制参数?
我需要以这种格式显示日期:dd/mm/yyyy。这实际上存储在 ASP.NET 文本框中,并用作 GridView 上选择的控制参数。但是,运行查询时,日期格式应更改为“d M y”(对于 Oracle)。它不起作用。有人可以告诉我我做错了什么吗?现在我正在将“新”格式推送到不可见标签并使用该标签作为我的控制参数:
$(document).ready(function() {
//datepicker for query, shown traditionally but holding an Oracle-needed format
$('[id$=txtBeginDate]').datepicker({ minDate: -7 , altFormat: 'd M y' });
//get alt format
var altFormat = $('[id$=txtBeginDate]').datepicker("option", "altFormat");
//set date to be altformat
$('[id$=lblActualDate]').datepicker("option", "altFormat", 'd M y');
});
I have the need to display a date in this format: dd/mm/yyyy. This is actually being stored in an ASP.NET textbox and being used as a control parameter for a select on the GridView. When the query is run, though, the date format should change to 'd M y' (for Oracle). It is not working. Can someone tell me what I'm doing wrong? Right now I am pushing the "new" format to a invisible label and using the label as my control param:
$(document).ready(function() {
//datepicker for query, shown traditionally but holding an Oracle-needed format
$('[id$=txtBeginDate]').datepicker({ minDate: -7 , altFormat: 'd M y' });
//get alt format
var altFormat = $('[id$=txtBeginDate]').datepicker("option", "altFormat");
//set date to be altformat
$('[id$=lblActualDate]').datepicker("option", "altFormat", 'd M y');
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不在构建 Oracle 查询时在服务器端进行格式化?
why not do the formatting on the server-side when building your Oracle query?
SqlDataSource 只能使用服务器端 asp.net 控件作为 ControlParameters。要使用 jQuery 日期选择器,您必须有点花哨。
放置一个普通参数,然后处理 SqlDataSource 的 Selecting 事件,以手动设置来自 Request 对象的参数值(具有适当的验证和格式设置)。
SqlDataSource can only use server-side asp.net controls for ControlParameters. To use your jQuery datepicker, you'll have to get a little fancy.
Put a plain Parameter and then handle the SqlDataSource's Selecting event to set the value for the parameter from the Request object (with suitable validation and formatting) by hand.