问题描述
我有一个链接按钮作为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 date = DateTime.Now;
date = date.AddMonths(-1);
YourLabelID.Text = string.Format("{0:MMMM}", date);
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");
}
这篇关于如何通过单击按钮连续获得上个月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!