c#
  • asp.net
  • gridview
  • 2014-02-13 44 views 0 likes 
    0

    編輯:我通過包括在我的GridView的filterexpression和搜索文本框解決了這個問題。這樣我就可以直接傳遞搜索查詢,而不用做各種各樣的花哨的東西。負載特定的GridView行


    我做了一個基本的搜索功能。在這種searchfunction,我已經包括一個超鏈接以查看詳細信息:

    <asp:HyperLink ID="lnkSelect" runat='server' NavigateUrl='<%# String.Format("~/CompanyActive.aspx?id={0}", Eval("CompanyID")) %>'>Select</asp:HyperLink> 
    

    它通過對CompanyID我的炫魅(CompanyActive)在那裏我有分頁一個gridview。

    但我的問題是,它沒有去到具體頁面/地方記錄的位置。它只是顯示第一頁。

    我覺得我需要把某種代碼插入CompanyActive我的頁面加載事件,但我不知道我應該使用哪些命令。

    +0

    張貼您的導航頁面代碼。 – codebot

    +0

    導航頁面代碼?你的意思是我的分頁設置爲gridview? – dQlle

    +0

    你的意思是你想顯示具體的id存在的頁面? – Jumpei

    回答

    2

    您使用一個數據表來填補你的GridView?

    如果是的話,你知道該ID是不會改變,你可以做記錄ID

    這裏的導航是一個類似的問題的鏈接#2

    How to go to particular record in gridview

    希望這有助於

    馬丁

    您正在使用這個作爲你的鏈接按鈕

    <asp:HyperLink ID="lnkSelect" runat='server' NavigateUrl='<%# String.Format("~/CompanyActive.aspx?id={0}", Eval("CompanyID")) %>'>Select</asp:HyperLink> 
    

    使用來自其他文章的代碼只需修改這樣

    private void BindProductGrid() 
        { 
    product ID = Request.QueryString["id"]; // id is the name same as what you passed as a querystring 
         DataTable tblProducts = getAllProducts(); 
         GridProducts.DataSource = tblProducts; 
         bool needsPaging = (tblProducts.Rows.Count/GridProducts.PageSize) > 1; 
    
         if (ProductID == -1) 
         { 
          this.GridProducts.PageIndex = 0; 
          this.GridProducts.SelectedIndex = -1; 
         } 
         else 
         { 
          int selectedIndex = tblProducts.AsEnumerable() 
           .Select((Row, Index) => new { Row, Index }) 
           .Single(x => x.Row.Field<int>("ProductID") == ProductID).Index; 
          int pageIndexofSelectedRow = (int)(Math.Floor(1.0 * selectedIndex/GridProducts.PageSize)); 
          GridProducts.PageIndex = pageIndexofSelectedRow; 
          GridProducts.SelectedIndex = (int)(GridProducts.PageIndex == pageIndexofSelectedRow ? selectedIndex % GridProducts.PageSize : -1); 
         } 
         GridProducts.DataBind(); 
        } 
    

    這樣的代碼中的ID是你通過了公司ID另一頁

    +0

    沒有數據表。 我的gridview中的所有東西都通過sqldatasource填充。 ID永遠不會改變,因爲它是我數據庫中的主鍵。 – dQlle

    +0

    好的,在這種情況下,該文章應該仍然工作,因爲您知道確切的ID –

    +0

    但是,我怎樣才能將代碼綁定到兩個單獨的頁面?我有兩個網站,搜索和公司主動。超鏈接位於搜索。 該文章是關於如果gridview和按鈕位於同一頁面上。或者我完全錯誤? – dQlle

    相關問題