データベースからスケジュールを印刷してループを使用しています。私はaspでこれを行っているが、私はC#asp.netに変わり、問題を抱えている。裁判所| |法廷|裁判所の数に基づいて裁判所C#ASP.net変数がスコープ内でスコープから外れる
それはゲームを印刷し
まず私は
時間はスケジュールヘッダを印刷します。 次のレコードの現在の日付は、テーブル行全体にわたって日付を出力する最後の日付とは異なります。 それから、現在のレコードの時刻と最後の時刻が同じであるかどうかを確認し、時刻を出力していない場合はゲームレコードを表示します。
私の問題は、私が時間外にstatmentを使用しようとしたときに、その時点でTableRowを宣言しているということです。 if文の外にtablerowを置くと、正しく印刷されません。
これは私が持っているものです。
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);
}
}
私はまた、あなたが、私が達成しようとしているかを確認するためにwww.swgc.ca/volleyball/2011/schedules.aspに行くことができます...それが役立つならば、私は現在、ASPで持っているもの投稿することができます。
おかげ
このコードは、読みやすくするために省略してください。 – adt