検索クエリを処理するスクリプトがあります。結果は並べ替え可能なヘッダーで返されるため、ロット # 列のタイトルをクリックすると、ロット # ASC で結果が並べ替えられます。ただし、既に ASC (これはセッション変数に格納されています) でソートされている場合は、ロット # DESC でソートするように変更されます (そしてそのセッション変数が更新されます)。
サムネイルが検索結果に含まれていない限り、これらはすべて完全に機能します。それらを含めると(検索クエリを変更して画像パスを含め、画像列の画像を出力するだけです)、すべてが壊れます。何が起こるかは次のとおりです。
ページが読み込まれたら、response.write(Session["sort"])
どのように並べ替えているか (ASC または DESC) を確認します。
列ヘッダーがクリックされた場合、新しい「order by」列が既に「order by」列であったかどうかを確認します (これもセッション変数に保存されますSession["orderby"]
)。
以前に order by 変数として設定されていなかった場合は、sort セッション変数が ASC に設定され、order by セッション変数が列名に設定されます。
以前に order by 変数として設定されていた場合は、現在の並べ替えセッション変数が何に等しいかを確認します。ASC に等しい場合は、並べ替えセッション変数を DESC に設定し、セッション変数による順序は同じままです。DESC と等しい場合、ソート セッション変数を ASC に設定し、order by 変数は同じままです。
この部分は実際にはまだ機能します。response.write(Session["sort"])
問題は、ページの処理の最後に、変数が何に設定されているかをもう一度確認することです。これは、ページが画面に読み込まれる前に行われる最後の処理です。そのため、ページがヒットしたときに最初に行われるのはソート セッション変数の出力であり、最後に行われるのは変数の再出力です。
そのため、画像がページに含まれている場合、1 つの列をクリックすると、ASC または DESC のいずれかで並べ替えられます (クリックした列に応じて、他のすべての列と交互に表示されるように見えます)。したがって、クリックした列によって最初の列response.write(Session["sorty"])
が空白になり (まだ設定されていないため)、2 番目の列が ASC を出力したとします。列をもう一度クリックすると、最初に DESC (最後に印刷されたものと最初に印刷されたものとの間で何も変更されていないため、ASC である必要があります) が出力され、2 番目に再度 ASC が出力されます。
そのため、最後の印刷と最初の印刷の間にページ処理がまったくない場合、ページの読み込み間でセッション変数が変更されています。(そして、1 つおきの列では逆になり、ASC が一番上に表示され、DESC が一番下に表示されます。) 繰り返しますが、これは画像がなくても完全に機能します。
サムネイル インクルード スクリプトを含む唯一のコードは次のとおりです。
if (Session["incThumb"] != null)
{
resultText += "<table style=\"width:100%;\">\n<tr style=\"font-weight:bold;text-align:left;\">\n<th style=\"border-bottom:1px solid #000;\">Thumb</th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_id\">Item ID</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=item_title\">Title</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_lot\">Lot</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_cs_txt_id\">Consignor ID</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblMcat.mcat_name\">Master Category</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblCat.cat_name\">Category</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_est_lo\">Low Est.</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_est_hi\">High Est.</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_reserve\">Reserve</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_status\">Status</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_pr\">Hammer Price</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblMailList.mail_ID\">Bidder ID</a></th>\n</tr>\n";
}
else
{
resultText += "<table style=\"width:100%;\">\n<tr style=\"font-weight:bold;text-align:left;\">\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_id\">Item ID</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=item_title\">Title</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_lot\">Lot</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_cs_txt_id\">Consignor ID</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblMcat.mcat_name\">Master Category</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblCat.cat_name\">Category</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_est_lo\">Low Est.</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_est_hi\">High Est.</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_reserve\">Reserve</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_status\">Status</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_pr\">Hammer Price</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblMailList.mail_ID\">Bidder ID</a></th>\n</tr>\n";
}
次に、このすぐ下に、SQL の結果を出力するときにも考慮します。これは (英語で)、サムネイルを含めるためのセッション変数が null でない場合、サムネイル用の余分なテーブル セルを含め、画像に追加します。
言うまでもなく、これは私を困惑させました。すべての応答/コメントをいただければ幸いです。他のコードを見たい場合はお知らせください。
編集
response.write コードは次のとおりです。
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Session["sort"] + " 1<br/>");
string orderBy = "";
base.SubNavItems.Add("Search Home", "searchHome.aspx");
if (!IsPostBack)
{
}
if (!String.IsNullOrEmpty(Request.QueryString["page"]))
{
if (!String.IsNullOrEmpty(Request.QueryString["orderBy"])){
orderBy = Request.QueryString["orderBy"].ToString();
}
get_page(Int32.Parse(Request.QueryString["page"].ToString()), orderBy);
}
if (!String.IsNullOrEmpty(Request.Form["ctl00$ContentPlaceHolder1$save"]))
{
click_search();
}
Response.Write(Session["sort"] + " 1<br/>");
}
したがって、ページは常に列ヘッダーに設定されるため、列get_page()
を並べ替えるとメソッドが呼び出されます。 クエリ文字列を介して設定され、以下のコードを含むorderBy
メソッドに渡されます。protected void get_page(Int32 page, String orderBy)
そのメソッドの最後には、メソッドがResponse.Write(Session["sort"] + " 2<br/>");
最後に行う行もあります。この時点では、他のメソッドは実行されません。また、.aspx ページからソート変数を出力したところ、.aspx.cs ページが出力する変数の最後の出力と同じ結果が得られました (これは、次に出力される最初のものとは異なります)。
先に進んで、order by/sort 全体にロジックを追加すると思います。
if (Session["orderBy"] != null)
{
if (Session["orderBy"].ToString() == orderBy)
{
if (Session["sort"].ToString() == "ASC")
{
Session["sort"] = "DESC";
}
else
{
Session["sort"] = "ASC";
}
}
else if (!String.IsNullOrEmpty(orderBy))
{
Session["sort"] = "ASC";
Session["orderBy"] = orderBy;
}
}
else if (!String.IsNullOrEmpty(orderBy))
{
Session["sort"] = "ASC";
Session["orderBy"] = orderBy;
}
else
{
Session["sort"] = "ASC";
Session["orderBy"] = "tblItem.item_id";
}