0
我正在製作一個網上商店程序,它是視覺工作室c#中非常基本的程序。我有一個工作搜索,我正在嘗試不僅將結果打印到表格中,而且還將每個結果都可點擊重定向到項目頁面以獲取更詳細的信息。C#將結果打印到表格中
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace BookStoreOnline
{
public partial class WebForm2 : System.Web.UI.Page
{
private static Database dBase;
private static string test;
private static string testInfo;
private static List<Book> resultList;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (SearchBox.Text != "")
{
dBase = new Database();
resultList = new List<Book>();
test = SearchCriteria.SelectedItem.Text;
testInfo = SearchBox.Text;
switch (test)
{
case "ISBN":
resultList = dBase.SearchISBN(testInfo);
break;
case "Title":
resultList = dBase.SearchTitle(testInfo);
break;
case "Author":
resultList = dBase.SearchAuthor(testInfo);
break;
case "Semester":
resultList = dBase.SearchSemester(testInfo);
break;
case "Course":
resultList = dBase.SearchCourse(testInfo);
break;
case "Section":
resultList = dBase.SearchSection(testInfo);
break;
case "Professor":
resultList = dBase.SearchProfessor(testInfo);
break;
case "CRN":
resultList = dBase.SearchCRN(testInfo);
break;
}
if (resultList.Count == 0)
{
NoResults.Text = "No results were found.";
}
else
{
Results.Text = "";
for (int i = 0; i < resultList.Count; i++)
{
int j = i + 1;
}
}
}
}
}
}
我已經打印出像這樣的結果,但我不能讓每個單獨的項目以任何方式鏈接到他們的更多信息頁面。
//Results.Text += "<pre>" + j + ". Title: " + resultList[i].Title + "<br>" + "Author: " + resultList[i].Author + "<br><br>" + </pre>";
構建超鏈接(使用''元素)取決於您的物品詳細信息頁面接受的參數。 – Filburt
這是純粹的內部(我相信這是正確的詞),所以它實際上不會超鏈接。相反,它將使用Response.Redirect(「BookInfo.aspx」)並跟蹤在會話中選擇哪本書以顯示信息。 – NBera
超鏈接對內部事物也同樣適用,它確實是在Web應用程序中執行此類事情的方式。 – DWright