How to use jQuery datepicker as a control parameter for SqlDataSource?
I have the need to display a date in this format: dd/mm/yyyy. This is actuall开发者_运维问答y 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');
});
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")
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.
精彩评论