2017-07-25 32 views
0

我正在嘗試搜索,並且我的網格顯示了20條記錄的結果。如何在頁面底部的點擊數中分頁查看第2頁

如果我已經申請允許分頁真,頁面大小爲20

然後在點擊中網第2頁上我的整個電網再次向我展示全網以其第1頁清爽答。

如何查看我的最後10條記錄這是從11到20,如果記錄是20和頁面大小是電網

<div id="divApplication" runat="server"> 
    <asp:GridView ID="gvApplication" 
     runat="server" 
     AutoGenerateColumns="false" 
     AllowPaging="true" 
     AllowSorting="True" 
     AlternatingRowStyle-CssClass="alt" 
     PagerStyle-CssClass="pgr" 
     OnPageIndexChanging="OnPageIndexChanging" 
     CssClass="table table-bordered table-striped" 
     PageSize="10" Width="50%"> 

     <Columns> 
      <asp:TemplateField HeaderText='Application' HeaderStyle-VerticalAlign="Middle"> 
       <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" CssClass="chkbox" /> 
       <ItemTemplate> 
        <asp:Label ID="lblFirstName" runat="server" 
         att='<%#DataBinder.Eval(Container.DataItem,"ID")%>' Text='<%# SetLinkCodeApplication(Convert.ToInt64(DataBinder.Eval(Container.DataItem,"ID")),DataBinder.Eval(Container.DataItem,"Application").ToString()) %>'></asp:Label> 
       </ItemTemplate> 
       <ItemStyle Width="3%" HorizontalAlign="left" /> 
      </asp:TemplateField> 
     </Columns> 

    </asp:GridView> 
</div> 

的10

客戶端代碼綁定我的網格在C#中的服務器端代碼

public void fncfillApplication() 
{ 
    try 
    { 
     DataSet ds = new DataSet(); 
     ds.ReadXml(Server.MapPath("Application.xml")); 
     if (ds.Tables[0].Rows.Count != 0) 
     { 
      gvApplication.DataSource = ds; 
      gvApplication.DataBind(); 
     } 
    } 
    catch (Exception ex) 
    { 
     ex.Message.ToString(); 
    } 
} 

protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e) 
{ 
    gvApplication.PageIndex = e.NewPageIndex; 
    this.fncfillApplication(); 
} 

Setlinkcode在編輯模式綁定我的數據

public string SetLinkCodeApplication(Int64 sId, string sName) 
{ 
    string functionReturnValue = null; 
    try 
    { 
     functionReturnValue = "<a href=javascript:fncopenEditPopUpApplication(" + sId + ")>" + sName.Trim() + "</a>"; 
     //return functionReturnValue; 
    } 
    catch (Exception ex) 
    { 
     throw; 
    } 
    return functionReturnValue; 
} 

我使用XML數據源綁定數據

+0

測試你的代碼。它工作得很好。 – VDWWD

+0

在搜索它顯示我20結果,但當我點擊第二個索引查看最後10條記錄綁定再次發生,並顯示我所有記錄 – Basant12

+0

其工作正常,但是當搜索比如果網格填充20條記錄,但如果頁面大小是20比我不能查看最後10條記錄 – Basant12

回答

0

我認爲你應該使用

XDocument document = XDocument.Load(@"c:\users\administrator\documents\visual studio 2010\Projects\LINQtoXMLSelectApp\LINQtoXMLSelectApp\Employee.xml"); 
     var query = from r in document.Descendants("Employee") where (int)r.Element("Age") > 27 select new 
     { 
      FirstName = r.Element("FirstName").Value, Age = r.Element("Age").Value }; 
     GridView1.DataSource = query; 
     GridView1.DataBind(); 
+0

我正在使用.net框架2.0我不支持LINQ – Basant12

+0

是的LINQ支持min .net framework 3.5 –

0

您的問題不生產我。它工作正常。我已經使用下面的XML文件綁定到gridview。代碼和HTML是一樣的。

<?xml version="1.0" encoding="utf-8" ?> 
<Customer> 
    <Customerinfo> 
    <Name>Vithal Wadje</Name> 
    <city>Mumbai</city> 
    <Address>Sion, Mumbai</Address> 
</Customerinfo> 
    <Customerinfo> 
    <Name>D Sudhir Wadje</Name> 
    <city>Latur</city> 
    <Address>Latur</Address> 
    </Customerinfo> 
    <Customerinfo> 
    <Name>U D</Name> 
    <city>Mumbai</city> 
    <Address>DN,Road Mumbai</Address> 
    </Customerinfo> 
    <Customerinfo> 
    <Name>Anil Kumar</Name> 
    <city>Delhi</city> 
    <Address>Nehru House</Address> 
    </Customerinfo> 
<Customerinfo> 
    <Name>Five</Name> 
    <city>Mumbai</city> 
    <Address>Sion, Mumbai</Address> 
</Customerinfo> 
<Customerinfo> 
    <Name>Six</Name> 
    <city>Mumbai</city> 
    <Address>Sion, Mumbai</Address> 
</Customerinfo> 
<Customerinfo> 
    <Name>Seven</Name> 
    <city>Mumbai</city> 
    <Address>Sion, Mumbai</Address> 
</Customerinfo> 
<Customerinfo> 
    <Name>Eight</Name> 
    <city>Mumbai</city> 
    <Address>Sion, Mumbai</Address> 
</Customerinfo> 
<Customerinfo> 
    <Name>Nine</Name> 
    <city>Mumbai</city> 
    <Address>Sion, Mumbai</Address> 
</Customerinfo> 
<Customerinfo> 
    <Name>Ten</Name> 
    <city>Mumbai</city> 
    <Address>Sion, Mumbai</Address> 
</Customerinfo> 
<Customerinfo> 
    <Name>Eleven</Name> 
    <city>Mumbai</city> 
    <Address>Sion, Mumbai</Address> 
</Customerinfo> 
<Customerinfo> 
    <Name>Twelve</Name> 
    <city>Mumbai</city> 
    <Address>Sion, Mumbai</Address> 
</Customerinfo>  
</Customer> 
0

我認爲它可以幫助您

ds.Tables[0].Select("ID=1 AND ID2=3");