简体   繁体   English

Gridview Paging ASP.NET 与 Gridview 外的 Pager Panel

[英]Gridview Paging ASP.NET with Pager Panel outside Gridview

This is my first time for using ASP.NET to develop website.这是我第一次使用 ASP.NET 开发网站。

I want to show my data from database in a GridView with Paging function and I can implement it by using OnPageIndexChanging="GridView1_PageIndexChanging" but I want to use my own pager so the question is我想在带有分页功能的 GridView 中显示我的数据库数据,我可以通过使用OnPageIndexChanging="GridView1_PageIndexChanging"来实现它,但我想使用我自己的寻呼机,所以问题是

"How can I link my pager (the right bottom in the pic) to the gridview instead the pager which generated by the ASP.NET" “如何将我的寻呼机(图片中的右下角)链接到 gridview 而不是由 ASP.NET 生成的寻呼机”

Pics:图片:图片

This is my code in aspx这是我在 aspx 中的代码

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CssClass="table table-bordered table-condensed table-striped table-primary table-vertical-center"
        PageSize="3" AllowPaging="True"
        OnPageIndexChanging="GridView1_PageIndexChanging">
         <Columns>
              <asp:BoundField DataField="UNIT_ID" HeaderText="รหัส" SortExpression="unitid">
              <HeaderStyle CssClass="center" />
              <ItemStyle Width="10%" CssClass="center" />
              </asp:BoundField>
         </Columns>                                                                    
      </asp:GridView>
     </ContentTemplate>
</asp:UpdatePanel>

Code in cs cs中的代码

public partial class _Default : Page
{
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                bindGridView();  
        }

        protected void bindGridView() {
            string sqltxt = "select * from drug_units"; //where UNIT_ID =:unitid";
            CommandData comm = new CommandData();
            comm.SetCommandText(sqltxt);
            //comm.AddInputParameter("unitid", "5");
            List<DrugsUnit> dy = new List<DrugsUnit>();
            comm.ExecuteNonQuery();
            dy = comm.ExecuteToList<DrugsUnit>();
            GridView1.DataSource = dy;
            /*BoundField boundField = new BoundField();
            boundField.DataField = "UNIT_ID";
            boundField.HeaderText = "ID";
            boundField.SortExpression = "ID";
            boundField.HeaderStyle.CssClass = "center";
            boundField.ItemStyle.CssClass = "center";
            GridView1.Columns.Add(boundField);*/
            GridView1.DataBind();
            GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            bindGridView();
        }
 }
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Pager)
    {
        upGridPager.Update();
        e.Row.SetRenderMethodDelegate(new RenderMethod((w, r) =>
        {
            e.Row.SetRenderMethodDelegate(null);
            using (var ms = new StringWriter())
            using (var writer = new HtmlTextWriter(ms))
            {
                e.Row.RenderControl(writer);
                GridPager.InnerHtml = "<table>" + ms.ToString() + "</table>";
            }
        }));
}

The aspx could look like this (outside of your grid) aspx可能看起来像这样(在您的网格之外)

<asp:UpdatePanel ID="upGridPager" runat="server" UpdateMode="Conditional">
   <ContentTemplate>
     <div runat="server" id="GridPager" />
   </ContentTemplate>
</asp:UpdatePanel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM