在 `ItemTemplate` 中以逗號或特定分隔符串聯多欄位:
<asp:LinkButton ID="lnkEdit" runat="server"
CommandArgument='<%# Eval("DictID") + "|" + Eval("DictType") %>'
CommandName="Edit" Text="編輯" />
protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
string[] args = e.CommandArgument.ToString().Split('|');
string dictId = args[0];
string dictType = args[1];
Response.Redirect($"Edit.aspx?id={dictId}&type={dictType}");
}
}
<a href='Detail.aspx?id=<%# Eval("DictID") %>&type=<%# Eval("DictType") %>'>詳情</a>
目標頁面:
string id = Request.QueryString["id"];
string type = Request.QueryString["type"];
<asp:Button ID="btnGo" runat="server" Text="去目標頁"
PostBackUrl="~/TargetPage.aspx" />
目標頁面 (`TargetPage.aspx`) 取值:
public partial class TargetPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
// 1. 找控制項 (需在來源頁面 public property 或 FindControl)
TextBox txt = (TextBox)PreviousPage.FindControl("txtSource");
string val = txt?.Text;
// 2. 或直接存取 Public Property (來源頁面需宣告 public string MyProp { get; })
// string val = ((SourcePage)PreviousPage).MyProp;
}
}
}
| 技術 | 適用場景 | 生命週期 |
|---|---|---|
| Session | 大量資料、敏感資訊、多步驟精靈 | Session 存活期間 |
| Cache | 暫存共享資料、效能優先 | 依過期策略 |
| Context.Items | Server.Transfer 同一請求內傳遞 | 單一請求 |
| Cookie | 跨瀏覽器分頁、持久化偏好 | 依 Expires |
| HiddenField + PostBack | 同頁面回傳攜帶額外值 | 單一回傳 |