2012-06-29 15 views
1

我有一個網站,有產品列表頁和商品詳細頁。如何使提交時將值傳遞給另一個aspx頁的自動完成文本框?

在ASP主頁我放在一個文本框來搜索數據庫中的產品。

什麼,我需要做的是:當訪問者開始在文本框中書寫,從數據庫中的產品名稱的文本框auocompletes。

當訪問者按從下拉列表結果進入後,網站需要他通過從ID由從主頁查詢字符串中傳遞的提交產品的詳細信息填寫產品詳細信息頁面。

請幫助我,我搜索了很多,還有一些沒有我的情況的工作非常類似的問題。

任何鏈接到一個教程或像我的另一個問題,這裏將是完美的。

非常感謝你

+2

你需要向我們展示一些代碼來弄清楚爲什麼許多類似答案不適合你。 – Widor

回答

1

你需要automcompleteextender。閱讀關於它在

  1. CodeProject上的教程here
  2. 正式文件here
  3. MSDN教程正好覆蓋您的需求here
1

我會檢查出jQuery autocomplete

你可以使用這樣的:

$('#<%= yourTextBox.ClientID %>').autocomplete({ 
    source: 'HandlerThatReturnsProductNames.ashx', 
    select: function (event, ui) { 
     // this is where you would jump to your product page 
    } 
}); 

然後你需要創建通用處理器「HandlerThatReturnsProductNames.ashx」。在ProcessRequest方法就需要做這樣的事情:

public void ProcessRequest(HttpContext context) { 

    string term = context.Request.QueryString.Get("term"); 

    List<QuickProduct> listOfProducts = SomeMethodThatGetsMatchingProducts(term); 
    var jsSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); 
    string json = jsSerializer.Serialize(listOfProducts); 

    context.Response.ContentType = "application/json"; 
    context.Response.Write(json); 
    context.Response.End(); 
} 

假設你QuickProduct是這樣的:

public class QuickProduct { 
    public int value { get; set; } 
    public string label { get; set; } 
} 
相關問題