没有PostBack的分页 [英] Paging Without PostBack

查看:52
本文介绍了没有PostBack的分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是asp.net的初学者。我需要在没有任何回复的情况下进行分页。我正在使用Visual Studio 2008 ..我的示例代码如下...有人可以帮忙吗?



这是我的ASPX代码









 <   p  >  
< fieldset >

< div >
< 表格 >


< / table > ;

< asp:DataGrid ID = GridView1 HeaderStyle-BackColor = #3AC0F2 HeaderStyle-ForeColor = 白色 < span class =code-attribute>

< span class =code-attribute> RowStyle-BackColor = #A1DCF2 AlternatingRowStyle-BackColor = 白色 AlternatingRowStyle-ForeColor = #000

runat = server AutoGenerateColumns = false AllowPaging = true 宽度 = 800px

< span class =code-attribute>

< span class =code-attribute> < span class =code-attribute> >



< >
< asp:TemplateColumn >
< HeaderStyle 宽度 = 25px > < / HeaderStyle >
< HeaderTemplate >
< asp:CheckBox ID = CheckAll language = javascript onclick = return CheckAll_onclick(this.checked)

Runat = server / >
< / HeaderTempla te >
< ItemTemplate >
< asp:CheckBox ID = DeleteThis language < span class =code-keyword> = javascript onclick = 返回DeleteThis_onclick(this.checked)

< span class =code-attribute> runat = server / < span class =code-keyword>>
< / ItemTemplate >
< / asp:TemplateColumn >

< asp:BoundColumn HeaderText = 名称 DataField = 名称 > < / asp:BoundColumn >

<% - < asp:BoundColumn HeaderText =DateDataField =Date>< / asp:BoundColumn> - %>





< asp:TemplateColumn >
< ItemTemplate >
< asp:TextBox 文本 =' <% #DataBinder.Eval(Container.DataItem, 日期)%>' ID = Calender2 runat = server CssClass = ControlStyle

< span class =code-attribute> 宽度 = 150px > < / asp:TextBox >
< a href = java<! - no - >脚本:NewCssCal('Calender1','ddmmyyyy') >
< img id = Img1 runat = server align = middle

src = cal.gif 样式 = 宽度:17px;高度:16px / > < / a > < / td >
< / ItemTemplate >
< / asp:TemplateColumn > ;





< asp:TemplateColumn >
< HeaderStyle 宽度 = 100px > < span class =code-keyword>< / HeaderStyle >
< HeaderTemplate >
查看
< / HeaderTemplate > ;
< ItemTemplate >
< asp:LinkBut​​ton HeaderText = 查看 ID = 查看 文字 < span class =code-keyword> =' <%#DataBinder.Eval(Container.DataItem , 名称)%>' DataField = 查看 runat = server OnClick = EditItem / >
< / ItemTemplate >
< / asp:TemplateColumn >
< asp:BoundColumn HeaderText = 描述 DataField = 说明 > < / asp:BoundColumn >


< /列 >




<% -
< Columns>
< asp:BoundField DataField =NameHeaderText =fNameItemStyle-Width =80/>
< asp:BoundField DataField =DateHeaderText =dateItemStyle-Width =150/>
< asp:BoundField DataField =ViewHeaderText =ViewItemStyle-Width =150/>
< asp:BoundField DataField =描述HeaderText =descriptionItemStyle-Width =150/>
< /列>
- %>
< / asp:DataGrid >


< / div >


< / fieldset >

< / p >











这是我的代码背后









< pre lang =c#> 


使用System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Xml;
使用System.Data;使用System.IO

;使用System.Xml.Linq

;
使用System.Configuration;

public partial class _Default:System.Web.UI.Page
{
XmlDocument xml = new XmlDocument();
protected void Page_Load(object sender,EventArgs e)
{
if(!this.IsPostBack)
{
this.BindGrid();
}
}

protected void loadButton_Click(object sender,EventArgs e)
{
string fileName = FileUpload1.FileName.Trim();
string date = Calender1.Text;
string description = TextBox1.Text;
//字符串视图=查看;


FileUpload1.PostedFile.SaveAs(Server.MapPath(NoticeFile //+ fileName));


XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath(Sample.xml));
XmlElement parentelement = xmldoc.CreateElement(Comments);

XmlElement name = xmldoc.CreateElement(Name);
name.InnerText = fileName;

XmlElement Date = xmldoc.CreateElement(Date);
Date.InnerText = date;



XmlElement描述= xmldoc.CreateElement(描述);
Description.InnerText = description;


XmlElement View = xmldoc.CreateElement(View);
View.InnerText = fileName;


parentelement.AppendChild(姓名);
parentelement.AppendChild(日期);
parentelement.AppendChild(查看);

parentelement.AppendChild(Description);

xmldoc.DocumentElement.AppendChild(parentelement);
xmldoc.Save(Server.MapPath(Sample.xml));
this.BindGrid();
// BindDatalist();
}




private void BindGrid()
{
using(DataSet ds = new DataSet())
{
ds.ReadXml(Server.MapPath(Sample.xml));
GridView1.DataSource = ds;
GridView1.DataBind();
}
}



protected void EditItem(object sender,EventArgs e)
{



LinkBut​​ton btn =(LinkBut​​ton)(发送者);

string yourValue = btn.Text;



//字符串b = Path.Combine(,a);

this.myPDFiFrame.Attributes [src] = Path.Combine(NoticeFile /,yourValue);




}




protected void GridView1_SelectedIndexChanged1(object sender,EventArgs e )
{
GridView1.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
}

解决方案

你也可以使用这些链接...网格视图中的javascript分页.. 。

从这些链接中你可以查看演示以及下载演示...





使用JQuery的客户端Gridview分页 [ ^ ]



http://www.aspsnippets.com/文章/分页在ASPNet-GridView-using-jQuery-AJAX.aspx [ ^ ]


for paging u可以使用pageindexchangeing事件,因为另一个人说..当然你说你不希望在分页上使用回发你应该将你的控件包装在更新面板中,或者简单的方法是使用一些jquery网格工具,比如



jqury datatablse / jqgrid以获得更好的性能。


将数据网格放在更新面板中,并将pageindexchanged事件注册到触发器。或者在onrowdatabound事件中注册它。它正在工作。

你的页面不会在postindexchanged事件上回发。

把你的代码放在内容中



 <   asp:UpdatePanel     ID   =  pnlupdate      runat  < span class =code-keyword> =  server   >  
< ContentTemplate >
< / ContentTemplate >
< / asp:UpdatePanel >


I am a beginner in asp.net. I need to do paging without any post back. And I am using Visual Studio 2008.. My sample code is below... Can anyone help please?

Here Is My ASPX code




  <p>
    <fieldset>
    
    <div>
    <table>
  
    
    </table>
    
   <asp:DataGrid  ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"

    RowStyle-BackColor="#A1DCF2" AlternatingRowStyle-BackColor="White" AlternatingRowStyle-ForeColor="#000"

    runat="server" AutoGenerateColumns="false" AllowPaging="true" Width = "800px"  

           

            >
    
  
    
     <Columns>
                <asp:TemplateColumn>
                  <HeaderStyle Width="25px"></HeaderStyle>
                  <HeaderTemplate>
                    <asp:CheckBox ID="CheckAll" language="javascript" onclick="return CheckAll_onclick(this.checked)"

                      Runat="server" />
                  </HeaderTemplate>
                  <ItemTemplate>
                    <asp:CheckBox ID="DeleteThis" language="javascript" onclick="return DeleteThis_onclick(this.checked)"

                      runat="server" />
                  </ItemTemplate>
                </asp:TemplateColumn>
                
                <asp:BoundColumn HeaderText="Name" DataField="Name" ></asp:BoundColumn>
                
             <%--   <asp:BoundColumn HeaderText="Date" DataField="Date"></asp:BoundColumn>--%>
                 
                 
                 
                 
                 
                 <asp:TemplateColumn>
                 <ItemTemplate>
                  <asp:TextBox Text='<%# DataBinder.Eval (Container.DataItem, "Date") %>' ID="Calender2" runat="server" CssClass="ControlStyle" 

                          Width="150px"></asp:TextBox>
                                <a href="java<!-- no -->script:NewCssCal('Calender1','ddmmyyyy')">
                    <img id="Img1"  runat="server" align ="middle"  

             src="cal.gif" style="width: 17px; height: 16px" /></a></td>
                 </ItemTemplate>
                  </asp:TemplateColumn>
                 
                 
                 
                 
                 
                 <asp:TemplateColumn>
                  <HeaderStyle Width="100px"></HeaderStyle>
                  <HeaderTemplate>
                   View
                  </HeaderTemplate>
                  <ItemTemplate>
                    <asp:LinkButton HeaderText="View" ID="View" Text='<%# DataBinder.Eval (Container.DataItem, "Name") %>'  DataField="View" runat="server" OnClick = "EditItem"/>
                  </ItemTemplate>
                </asp:TemplateColumn>
                  <asp:BoundColumn HeaderText="Description" DataField="Description"></asp:BoundColumn>
                  
                  
              </Columns>
       
    
       
    
   <%-- 
    <Columns>            
        <asp:BoundField DataField="Name" HeaderText="fName" ItemStyle-Width="80" />
        <asp:BoundField DataField="Date" HeaderText="date" ItemStyle-Width="150" />
        <asp:BoundField DataField="View" HeaderText="View" ItemStyle-Width="150" />
        <asp:BoundField DataField="Description" HeaderText="description" ItemStyle-Width="150" />
    </Columns>--%>
</asp:DataGrid>
    
    
    </div>
    
    
    </fieldset>
    
    </p>






And here is my Code Behind




<pre lang="c#">


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Data;

using System.IO;

using System.Xml.Linq;
using System.Configuration;

public partial class _Default : System.Web.UI.Page 
{
    XmlDocument xml = new XmlDocument();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.BindGrid();
        }
    }

    protected void loadButton_Click(object sender, EventArgs e)
    {
        string fileName = FileUpload1.FileName.Trim();
        string date = Calender1.Text;
        string description = TextBox1.Text;
      //  string view = "View";
       
        
        FileUpload1.PostedFile.SaveAs(Server.MapPath("NoticeFile//" + fileName));
        
  
        XmlDocument xmldoc = new XmlDocument();
        xmldoc.Load(Server.MapPath("Sample.xml"));
        XmlElement parentelement = xmldoc.CreateElement("Comments");
        
        XmlElement name = xmldoc.CreateElement("Name");
        name.InnerText = fileName;

        XmlElement Date = xmldoc.CreateElement("Date");
        Date.InnerText = date;

        

        XmlElement Description = xmldoc.CreateElement("Description");
        Description.InnerText = description;


        XmlElement View = xmldoc.CreateElement("View");
        View.InnerText = fileName;

        
        parentelement.AppendChild(name);
        parentelement.AppendChild(Date);
        parentelement.AppendChild(View);
       
        parentelement.AppendChild(Description);
       
        xmldoc.DocumentElement.AppendChild(parentelement);
        xmldoc.Save(Server.MapPath("Sample.xml"));
        this.BindGrid();
        //BindDatalist();
    }
    



    private void BindGrid()
{
    using (DataSet ds = new DataSet())
    {
        ds.ReadXml(Server.MapPath("Sample.xml"));
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
}



    protected void EditItem(object sender, EventArgs e)
    {



         LinkButton btn = (LinkButton)(sender);

         string yourValue = btn.Text;

        

      //  string b = Path.Combine("", a);

         this.myPDFiFrame.Attributes["src"] = Path.Combine("NoticeFile/", yourValue);




    }



 
    protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        GridView1.CurrentPageIndex = e.NewPageIndex;
        BindGrid();
    }
}

解决方案

you can also use these links...javascript paging in grid view...
From these links u can view demo as well as download demo...


Client Side Gridview Pagination using JQuery[^]

http://www.aspsnippets.com/Articles/Paging-in-ASPNet-GridView-using-jQuery-AJAX.aspx[^]


for paging u can use pageindexchangeing event as the other guy says ..however when you say you dont want to use postback on paging you should wrap your control inside update panel or easy way is to use some jquery grid tools like

jqury datatablse / jqgrid for better performance.


Put your datagrid in the update panel, and register the pageindexchanged event to the trigger. or register it wwhile in the onrowdatabound event. it is working.
your page will not be postback,on pageindexchanged event.
put your code in the content

<asp:UpdatePanel ID="pnlupdate", runat="server" >
            <ContentTemplate>
            </ContentTemplate>
            </asp:UpdatePanel>


这篇关于没有PostBack的分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆