我在视觉工作室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>";
答案 0 :(得分:-1)
您可以尝试使用DataGridView,每行一个按钮和CommandArgument。并重定向到您的产品详情页面。