データベースからスケジュールを印刷し、ループを使用しています。私はaspでこれを行いましたが、c#asp.netに変更して問題を抱えています。
まず、スケジュール ヘッダーを印刷します。
時間|裁判所|裁判所|裁判所
コートの数に基づいて、ゲームを印刷します。次に、現在のレコードの日付は、表の行全体に日付を印刷する最後の日付とは異なります。次に、現在のレコードの時間が前回と同じかどうかを確認し、そうでない場合は時間を出力し、ゲームの記録が同じ場合はゲームの記録を出力します。
私の問題は、時間 if ステートメントで TableRow を宣言しているため、別のステートメントで使用しようとすると範囲外になることです。テーブル行を if ステートメントの外に置くと、正しく印刷されません。
これが私が持っているものです。
for (int i = 0; i < GameCount; i++)
{
DateTime currentdatetime = (DateTime)Schedules.Tables["Schedule"].Rows[i]["datetime"];
string ndate = currentdatetime.ToString("MM/dd/yyy");
string ntime = currentdatetime.ToString("HH:mm");
string nextdate = currentdatetime.ToString("MM/dd/yyy");
if (i + 1 != GameCount)
{
DateTime nextdatetime = (DateTime)Schedules.Tables["Schedule"].Rows[i + 1]["datetime"];
nextdate = nextdatetime.ToString("MM/dd/yyy");
}
string TeamA = Schedules.Tables["Schedule"].Rows[i]["teamA"].ToString();
string TeamB = Schedules.Tables["Schedule"].Rows[i]["teamB"].ToString();
//check to see if date is current
if (LastDate != ndate)
{
TableRow daterow = new TableRow();
TableCell datecell = new TableCell();
datecell.ColumnSpan = 7;
datecell.Controls.Add(new LiteralControl(ndate));
daterow.Cells.Add(datecell);
ScheduleTable.Rows.Add(daterow);
LastDate = ndate;
}
//print the games
if (currentdatetime != LastDateTime)
{
TableRow gamerow = new TableRow();
TableCell timecell = new TableCell();
timecell.Controls.Add(new LiteralControl(ntime));
gamerow.Cells.Add(timecell);
if (i + 1 != GameCount & ndate != nextdate)
{
ScheduleTable.Rows.Add(gamerow);
}
}//check to see if next game is part of the current row
else
{
TableCell gamecell = new TableCell();
gamecell.Controls.Add(new LiteralControl(TeamA + ".vs." + TeamB));
gamerow.Cells.Add(gamecell);
}
}
また、現在 asp にあるものを投稿することもできます。
ありがとう