如何在页面底部的点击数中分页查看第2页

问题描述:

我正在尝试搜索,并且我的网格显示了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

我认为你应该使用

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 –

您的问题不生产我。它工作正常。我已经使用下面的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> 

我认为它可以帮助您

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