Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在标签上显示周日期_C#_Asp.net - Fatal编程技术网

C# 在标签上显示周日期

C# 在标签上显示周日期,c#,asp.net,C#,Asp.net,当用户单击日期时,我在标签上显示工作日。给出了相应的代码 C# protected void Calendar1\u selection已更改(对象发送方、事件参数e) { DateTime输入=Calendar1.SelectedDate; int delta=DayOfWeek.Sunday-input.DayOfWeek; DateTime firstDay=input.AddDays(增量); 对于(int i=0;i

当用户单击日期时,我在标签上显示工作日。给出了相应的代码

C#

protected void Calendar1\u selection已更改(对象发送方、事件参数e)
{
DateTime输入=Calendar1.SelectedDate;
int delta=DayOfWeek.Sunday-input.DayOfWeek;
DateTime firstDay=input.AddDays(增量);
对于(int i=0;i<6;i++)
Label2.Text+=((DateTime)(firstDay.Add(newtimespan(i,0,0))).ToSortDateString()+”;
}
ASPX

<asp:Calendar runat="server" ID="Calendar1" OnSelectionChanged="Calendar1_SelectionChanged" />
<asp:Label ID="Label2" runat="server" Text="" />

现在的问题是,每当我点击标签上的日期时,标签上的日期都会被覆盖,但每次它的书写日期都会在上一个日期旁边。理想情况下,应该在现有日期上写得过多

第二个问题是,我也想显示和获取周数


有什么想法吗?

我想你需要做的就是在SelectionChanged事件中将label2文本设置为空,即

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
       {
            DateTime input = Calendar1.SelectedDate;
            int delta = DayOfWeek.Sunday - input.DayOfWeek;
            DateTime firstDay = input.AddDays(delta);

            Label2.Text = string.Empty;

            for (int i = 0; i < 6; i++)
                Label2.Text += ((DateTime)(firstDay.Add(new TimeSpan(i, 0, 0, 0)))).ToShortDateString() + "  ";
        }
protected void Calendar1\u selection已更改(对象发送方、事件参数e)
{
DateTime输入=Calendar1.SelectedDate;
int delta=DayOfWeek.Sunday-input.DayOfWeek;
DateTime firstDay=input.AddDays(增量);
Label2.Text=string.Empty;
对于(int i=0;i<6;i++)
Label2.Text+=((DateTime)(firstDay.Add(newtimespan(i,0,0))).ToSortDateString()+”;
}

这包括你关于周数的问题。

成功了,谢谢你……但是第二期呢。我仍然停留在那你读了我引用的,有一个完整的源代码的例子。
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
       {
            DateTime input = Calendar1.SelectedDate;
            int delta = DayOfWeek.Sunday - input.DayOfWeek;
            DateTime firstDay = input.AddDays(delta);

            Label2.Text = string.Empty;

            for (int i = 0; i < 6; i++)
                Label2.Text += ((DateTime)(firstDay.Add(new TimeSpan(i, 0, 0, 0)))).ToShortDateString() + "  ";
        }