2012-04-30 15 views
2

獲取ID我有一個DataList和我通過URL發送用戶的用戶ID到另一個頁面:ASP.net - 從URL

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

和功能:

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

這個工程,但我是一種noobie,我不知道如何得到身份證,一旦我在下一頁。有任何想法嗎?

回答

4

你的代碼改成這樣ID

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

然後你就可以訪問用戶名是這樣的:

Request.QueryString["UserID"]; 

這裏是一個到QueryString on MSDN的鏈接。

+0

可以直接進入頁面加載WebForm3嗎? –

+0

請求查詢,我的意思是。 –

+0

是的。每個Webform都可以訪問Request對象。 – orandov

-1

使用會議並通過您的使用query string。然後從otherpage您可以輕鬆地訪問ID

0

應設置ID到url變量,就像這樣:

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

和其他頁面(WebForm3.aspx你的情況)用戶Request.Params或查詢字符串上獲得該值:

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 
    } 
}