如何通过单击按钮连续获得上个月 [英] How to get previous month continuously by clicking on button

查看:62
本文介绍了如何通过单击按钮连续获得上个月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个链接按钮作为PreviousMonth和一个显示当月的标签。因此,当用户点击该previousMonth链接按钮时,它应该显示上个月。



例如,如果当前月份是1月份,则应该在用户点击时显示为12月previousMonth如果用户再次点击PreviousMonth那么它应该显示为11月等等...........



你们可以请帮助吗我出去了。





谢谢

Manasa

Hi,

I have a link button as PreviousMonth and a label which displays the present month. So when user clicks on that previousMonth linkbutton,it should display previous month.

For ex,if present month is January and it should be displayed as december when user clicks on previousMonth and if user again clicks on PreviousMonth then it should be displayed as November and so on...........

Can you guys please help me out.


Thanks
Manasa

推荐答案

您可以使用 DateTime.AddMonths(按钮点击事件)执行此操作) [ ^ ]方法。

这是一个示例代码。



You can do this in the button click event by using the DateTime.AddMonths()[^] method to get the previous month.
Here is a sample code.

DateTime date = DateTime.Now;
date = date.AddMonths(-1);
YourLabelID.Text = string.Format("{0:MMMM}", date);


你可以这样做:



假设在页面加载中你显示当前标签控制月份如下:



You can do this:

Suppose in Page load you show current month in label control as given below :

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lblMonth.Text = System.DateTime.Now.ToString("MMM");
            }
        }





您可以在PreviousMonth按钮中写下以下代码点击以获取上个月:





You can write below code in Your "PreviousMonth" button click to get previous month:

protected void btnPreviousMonth_Click(object sender, EventArgs e)
        {
            DateTime tempDate = Convert.ToDateTime("01-"+ lblMonth.Text + "-2013"); 
            lblMonth.Text = tempDate.AddMonths(-1).ToString("MMM");
        }


这篇关于如何通过单击按钮连续获得上个月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆