Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
3.86/5 (3 votes)
See more:
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




ASP.NET
  <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();
    }
}
Posted
Updated 22-Jan-14 19:58pm
v4
Comments
$*Developer - Vaibhav*$ 23-Jan-14 1:40am    
Use the "GridView1_PageIndexChanging" event
JoCodes 23-Jan-14 1:58am    
Where is the Gridview in your Html Markup?

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[^]
 
Share this answer
 
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.
 
Share this answer
 
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

XML
<asp:UpdatePanel ID="pnlupdate", runat="server" >
            <ContentTemplate>
            </ContentTemplate>
            </asp:UpdatePanel>
 
Share this answer
 
Comments
smrafat 23-Jan-14 2:54am    
can u please give me any sample code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900