如何使用jQuery datepicker作为SqlDataSource的控制参数?

发布于 2024-08-26 01:38:49 字数 648 浏览 3 评论 0原文

我需要以这种格式显示日期: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

厌倦 2024-09-02 01:38:49

为什么不在构建 Oracle 查询时在服务器端进行格式化?

System.DateTime dt = DateTime.Parse(txtBeginDate.Text);
dt.ToString("dd MM yyyy")

why not do the formatting on the server-side when building your Oracle query?

System.DateTime dt = DateTime.Parse(txtBeginDate.Text);
dt.ToString("dd MM yyyy")
烏雲後面有陽光 2024-09-02 01:38:49

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文