2

データリストがあり、URLを介してユーザーのユーザーIDを別のページに送信しています。

<asp:HyperLink ID="LastNameLabel" runat="server" Text='<%# Eval("LastName") %>' NavigateUrl='<%# FormatUrl( (int) Eval("FriendsAccountID")) %>' />

および機能:

protected string FormatUrl(int FriendsAccountID)
{
    return "WebForm3.aspx?" + FriendsAccountID;
}

これは機能しますが、私は一種の初心者であり、次のページに移動した後、IDを取得する方法がわかりません。何か案は?

4

3 に答える 3

4

コードを次のように変更します。

protected string FormatUrl(int FriendsAccountID) { return "WebForm3.aspx?UserID=" + FriendsAccountID; }

次に、次のようにUserIDにアクセスできます。

Request.QueryString["UserID"];

これは、 MSDNのQueryStringへのリンクです。

于 2012-04-30T13:11:42.437 に答える
0

次のように、IDをそのurl変数に設定する必要があります。

protected string FormatUrl(int FriendsAccountID)
{
  return "WebForm3.aspx?FriendID=" + FriendsAccountID.ToString();
}

そして、他のページ(あなたの場合はWebForm3.aspx)で、ユーザーRequest.ParamsまたはQueryStringを使用して、その値を取得します。

protected void Page_Load(object sender, EventArgs e)
{
    int friendID = -1;

    if (Request.Params["FrientID"] != null && int.TryParse(Request.Params["FrientID"], out friendID)
    {
      // you got a valid friend id in friendID variable
    }
}
于 2012-04-30T13:13:31.660 に答える
-1

セッションを使用し、ID使用を渡します。query stringその後、他のページからそのIDに簡単にアクセスできます

于 2012-04-30T13:10:49.597 に答える