在 TemplateField 中用 Eval("categoryID") 構建超鏈接 List.aspx?categoryId=...,但後台 Request.QueryString["categoryId"] 取不到值。常見原因有三:
DataTable/實體類是否真有 categoryID(大小寫敏感),而非 CategoryId 或 cat_id。!IsPostBack 時綁定,且未在後續事件中重置。Request.RawUrl。// 前台頁面加載時打印調試
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
BindGrid();
}
// 檢查原始請求
System.Diagnostics.Debug.WriteLine("RawUrl: " + Request.RawUrl);
System.Diagnostics.Debug.WriteLine("categoryId: " + Request.QueryString["categoryId"]);
}
DataNavigateUrlFields + DataNavigateUrlFormatString 替代手動 Eval 拼接,減少錯誤。LinkButton + CommandArgument。