Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.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# 代码隐藏日历中的发布天数 //daysinastmonth给了我四月的天数 //DaysinCurrentMonth给了我五月的日子 公共无效运行日历(int STARTOFCALLENDER,int DAYSIN LASTMENT,int 日(当前月) { int值=0,startOfCalender1=0; 对于(int i=0;i_C#_Asp.net - Fatal编程技术网

C# 代码隐藏日历中的发布天数 //daysinastmonth给了我四月的天数 //DaysinCurrentMonth给了我五月的日子 公共无效运行日历(int STARTOFCALLENDER,int DAYSIN LASTMENT,int 日(当前月) { int值=0,startOfCalender1=0; 对于(int i=0;i

C# 代码隐藏日历中的发布天数 //daysinastmonth给了我四月的天数 //DaysinCurrentMonth给了我五月的日子 公共无效运行日历(int STARTOFCALLENDER,int DAYSIN LASTMENT,int 日(当前月) { int值=0,startOfCalender1=0; 对于(int i=0;i,c#,asp.net,C#,Asp.net,问题在于当前月份(即5月)没有显示应有的31天。无法思考如何解决此问题 您的问题是: //DaysinLastMonth gives me the Days in April //DaysinCurrentMonth gives me the Days in May public void RunCalender(int startOfCalender, int DaysinLastMonth,int

问题在于当前月份(即5月)没有显示应有的31天。无法思考如何解决此问题

您的问题是:

//DaysinLastMonth gives me the Days in April
//DaysinCurrentMonth gives me the Days in May



     public void RunCalender(int startOfCalender, int DaysinLastMonth,int 
                                                                DaysInCurrentMonth)
        {
            int value = 0, startOfCalender1 = 0;
            for (int i = 0; i < 6; i++)
            {
                HtmlTableRow tr = new HtmlTableRow();

                if (value == 0)
                   // StartOfCalender is the point where the Calender starts 
                   //from in the month display
                    startOfCalender1 = startOfCalender;
                else
                    startOfCalender1 = value;


                for (int j = 0; j < 7; j++)
                {
                    HtmlTableCell tc = new HtmlTableCell();
                    tc.BgColor = "#FAAFBE";
                    // tc.ColSpan = 1;
                    //tc.Attributes.Add("class", "rowA");
                    HtmlAnchor a = new HtmlAnchor();
                    a.HRef = "http://localhost:51955/Calender.aspx";

                    a.InnerHtml = startOfCalender1.ToString();

                    startOfCalender1 += 1;
                    if (startOfCalender1 == DaysinLastMonth + 1)
                    {
                        startOfCalender1 = 1;
                    }
                    value = startOfCalender1;
                    // Add the control to the TableCell
                    tc.Controls.Add(a);
                    // Add the TableCell to the TableRow
                    tr.Cells.Add(tc);
                }
                // Add the TableRow to the Table
                tbl.Rows.Add(tr);
            }
        }
在本例中,daysinastmonth==4月份的天数==30

因此,上面的
if
语句转换为:

if (startOfCalender1 == DaysinLastMonth + 1)
当从4月30日过渡到5月1日时,您希望使用这种逻辑

从5月30日过渡到5月31日时,您不希望使用此逻辑。

您的问题是:

//DaysinLastMonth gives me the Days in April
//DaysinCurrentMonth gives me the Days in May



     public void RunCalender(int startOfCalender, int DaysinLastMonth,int 
                                                                DaysInCurrentMonth)
        {
            int value = 0, startOfCalender1 = 0;
            for (int i = 0; i < 6; i++)
            {
                HtmlTableRow tr = new HtmlTableRow();

                if (value == 0)
                   // StartOfCalender is the point where the Calender starts 
                   //from in the month display
                    startOfCalender1 = startOfCalender;
                else
                    startOfCalender1 = value;


                for (int j = 0; j < 7; j++)
                {
                    HtmlTableCell tc = new HtmlTableCell();
                    tc.BgColor = "#FAAFBE";
                    // tc.ColSpan = 1;
                    //tc.Attributes.Add("class", "rowA");
                    HtmlAnchor a = new HtmlAnchor();
                    a.HRef = "http://localhost:51955/Calender.aspx";

                    a.InnerHtml = startOfCalender1.ToString();

                    startOfCalender1 += 1;
                    if (startOfCalender1 == DaysinLastMonth + 1)
                    {
                        startOfCalender1 = 1;
                    }
                    value = startOfCalender1;
                    // Add the control to the TableCell
                    tc.Controls.Add(a);
                    // Add the TableCell to the TableRow
                    tr.Cells.Add(tc);
                }
                // Add the TableRow to the Table
                tbl.Rows.Add(tr);
            }
        }
在本例中,daysinastmonth==4月份的天数==30

因此,上面的
if
语句转换为:

if (startOfCalender1 == DaysinLastMonth + 1)
当从4月30日过渡到5月1日时,您希望使用这种逻辑


从5月30日过渡到5月31日时,您不想使用此逻辑。

您确定它显示的月份正确吗?四月和六月都有30天。你是如何传递这些值的!你确定它显示的月份是正确的吗?四月和六月都有30天。你是如何传递这些值的!如果希望始终显示6行7天,则保持两个嵌套for循环。报废所有与
开始压延1
有关的物品。下次,请使用更好的变量名,如currentDayOfMonth或currentDate。不要使用int来跟踪当月的当前日期,否则您将需要实现所有这些日历逻辑。相反,使用DateTime,并为内部循环的每个迭代添加1天。DateTime类将自动知道如何从一个月过渡到下一个月然后你可以做
currentDate+=oneDay
(如果
currentDate
类型为
DateTime
),我已经按照您的建议@mbeckish做了,如何从我离开的地方继续移动到下一行,比如数字4Move
CurrentDayOfMonth=StartOfCalendar到方法顶部,在for循环之外。按照现在的方式,CurrentDayOfMonth将在每行的开头重置。如果希望始终显示6行7天,则将这两行嵌套为for循环。报废所有与
开始压延1
有关的物品。下次,请使用更好的变量名,如currentDayOfMonth或currentDate。不要使用int来跟踪当月的当前日期,否则您将需要实现所有这些日历逻辑。相反,使用DateTime,并为内部循环的每个迭代添加1天。DateTime类将自动知道如何从一个月过渡到下一个月然后你可以做
currentDate+=oneDay
(如果
currentDate
类型为
DateTime
),我已经按照您的建议@mbeckish做了,如何从我离开的地方继续移动到下一行,比如数字4Move
CurrentDayOfMonth=StartOfCalendar到方法顶部,在for循环之外。按照现在的方式,CurrentDayOfMonth将在每行的开头重置。