0

我正在尝试使用带有 asp.net 日历控件的 jquery 更改年份和月份,但我无法更改年份。可能是压光机控制属性有问题。

以下是我的代码

$(document).ready(function () {

    var cyear = $('#<%=Ddyear.ClientID %>');
    var cmonth = $('#<%=Ddmonth.ClientID %>');

    var cal = $('#<%=Calendar1.ClientID %>');
    cyear.change(function () {
        var item = cyear.val();
        var item2 = cmonth.val();

        item = item + ',' + item2;
        $.ajax({
            type: "POST",
            url: "dashboardQuery.aspx/calanderdates",
            data: '{item:"' + item + '"}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                var sdate = Date.parse(response.d, "MM/dd/yyyy");
                dates = sdate;
                $('#<%=Calendar1.ClientID %>').attr('VisibleDate', sDate);
            },
            error: function () {
                alert(msg.status);
            }
        });
    });
}); 
4

1 回答 1

0

VisibleDate不能通过 jQuery 在 ASP.Net 日历上设置属性,它是服务器端属性,因此生成的 HTML 中没有VisibleDate属性。

您可以更改代码以更改服务器端的日期,这样可以工作:

<asp:DropDown runat="server" ID="Ddmonth" OnSelectedIndexChanged="Ddmonth_SelectedIndexChanged" />

代码隐藏:

protected sub Ddmonth_SelectedIndexChanged(object sender, EventArgs e)
{
    // depending on what is in your drop down list will affect this code
    // this code assumes that you are listing the months by number, e.g. 1 for January, 2 for February, etc.
    int selectedMonth = int.Parse(DdMonth.SelectedValue);
    int monthsToAdd = selectedMonth - Calendar1.VisibleDate.Month;
    Calendar1.VisibleDate = Calendar1.VisibleDate.AddMonths(monthsToAdd);
}
于 2013-07-01T08:42:15.170 回答