2013-05-28 55 views
3

我有一個表tblProfile,它包含帶有Id,Name,Address的字段。我有2個aspx頁面,它們是Home.aspx和Here.aspx。在我Home.aspx我已經使用這個代碼傳遞的Id在我Here.aspx:查詢字符串到文本框

<asp:HyperLink ID="link" runat="server" NavigateUrl="Here.aspx?id={0}" 
      Font-Names="Times New Roman" Font-Size="Medium" >Click here</asp:HyperLink> 

在後面的代碼Home.aspx.cs:

protected void Page_Load(object sender, EventArgs e) 
{ 
    string bID = Request.QueryString["Id"]; 
    if (string.IsNullOrEmpty(Id)) 
    { 
     Response.Redirect("Here.aspx?", true); 
    } 
    ViewState["Id"] = Id; 
    link.NavigateUrl = String.Format(link.NavigateUrl, Id); 

} 

我沒有任何問題在第二頁將Id傳遞給url。但我現在想要的是,在我的Here.aspx中,我有3個文本框,它們應該由來自Home.aspx的特定Id的Id,Name和Address填充。嘗試了很多,但沒有運氣。任何幫助,將不勝感激。順便說一句,我用c#使用asp.net。

+0

你如何在你的'Here.aspx'頁面加載名字和地址?通過檢索數據庫或從'Home.aspx'頁面? – sarwar026

+0

你已經嘗試寫代碼,並讓我們知道你有什麼問題,當你嘗試... –

+0

你想發送名稱,地址爲Here.aspx,如果是這樣,嘗試像這樣點擊這裏 MahaSwetha

回答

0

從上評論您的回覆,我建議做到以下幾點:

  1. 通過您從查詢字符串
  2. 檢索顯示的Id負荷Here.aspx後端(cs文件)數據加載數據到你想要的文本框中。
0

您可以通過使用查詢字符串中的Id作爲關鍵字從數據庫中檢索配置文件數據來獲取名稱和地址。

protected void Page_Load(object sender, EventArgs e) 
{ 
    string profileID = Request.QueryString["Id"]; 
    // Retrive profile in your db.. 
    var profile = Profiles.Get(p => p.ProfileID == profileID); 

    // Populate the textboxes 
    txtId.Text = profileID; 
    txtName.Text = profile.Name; 
    txtAddress.Text = profile.Address; 
} 
1

我們正在爲它

方案1兩個解:

在Here.aspx的代碼背後

所以在asp.net用戶前頁屬性,這樣你就沒必要通過ID 。即

protected void Page_Load(object sender, EventArgs e) 
    { 
     // Find the name on the previous page 
     TextBox txt = (TextBox)Page.PreviousPage.FindControl("txtNameText"); 

     if (txt != null) 
      txtName.Text = Server.HtmlEncode(txt.Text); 
     else 
      txtName.Text = "[Name Not available]"; 
    } 

解決方案2:從查詢字符串獲取ID並在文本框中的文本property.i.e分配通過ID獲取數據。

protected void Page_Load(object sender, EventArgs e) 
     { 
      // Get value from query string 
      string profileID = Request.QueryString["Id"]; 

      // Fetch data from database by ID 
      DataTable dt = FetchEmployeeDataByID(ProfileID); 

      txtName.text = dt.rows[0]["Name"].tostring(); 

     }