从DB SQL Server ASP Net WebForms绑定jQuery UI Datepicker [英] Binding of jquery ui datepicker from db sql server asp net webforms
问题描述
我想在jquery datepicker中设置假期,而我一直尝试从
I want to set holiday in jquery datepicker and I've been try this code from jQuery UI Datapicker and dates from DB (asp.net)
function BindEvents() {
//Script for Calendar
var holiDays = [[2020, 25, 12, 'Christmas'], [2020, 7, 7, 'WEEKEND Event'], [2020, 7, 13, 'Some Holiday'], [2012, 7, 14, 'Festival']];
$(function () {
$('.datepicker').datepicker({
dateFormat: "yy-mm-dd",
beforeShowDay: noWeekendsOrHolidaysOrBlockedDates
});
function noWeekendsOrHolidaysOrBlockedDates(date) {
//var noWeekend = jQuery.datepicker.noWeekends(date);
return setHoliDays(date);
}
// set holidays function which is configured in beforeShowDay
function setHoliDays(date) {
var day = date.getDay();
if (day == 5 || day == 6) return [false, 'CalWeekEnd',];
for (i = 0; i < holiDays.length; i++) {
if (date.getFullYear() == holiDays[i][0]
&& date.getMonth() == holiDays[i][1] - 1
&& date.getDate() == holiDays[i][2]) {
return [false, 'holiday', holiDays[i][3]];
}
}
return [true, ''];
}
});
}
BindEvents();
并且我使用文本框显示jquery datepicker
and i use textbox to show jquery datepicker
<asp:TextBox ID="TextBox1" runat="server" CssClass="datepicker" />
<br />
如何从sql server中的数据库中调用var holidays
?
how to call var holidays
from database in sql server?
并且我也尝试过 https ://www.codeproject.com/Tips/740756/Binding-of-Calendar-Controls-from-Database ,但它使用日历控件而不是jquery datepicker
and i've been try this too https://www.codeproject.com/Tips/740756/Binding-of-Calendar-Controls-from-Database but it use calendar control not jquery datepicker
推荐答案
如果存在将数据库中的数据设置为此变量"holiDays"的问题.然后,您必须使用jquery ajax函数在代码端通过WebMethod从数据库中获取数据.
If there is an issue of setting an data from database to this variable "holiDays". Then you have to use jquery ajax function to fetch data from database by WebMethod in code side.
示例:如下所示.因此,此函数将从数据库中获取数据并在成功函数中显示结果.正如代码"console.log(result)"中提到的那样,您必须循环数据并将该数据推入数组以获得所需的相似结果.
Example : Like below. So this function will fetch data from database and show result in success function. As mention in code "console.log(result)" there you have to loop your data and push that data to array to get similar result as you want.
$.ajax({
type: "POST",
url: "Default.aspx/GetCustomers",
data: '',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
console.log(result);
},
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
这篇关于从DB SQL Server ASP Net WebForms绑定jQuery UI Datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!