hi guys i just want to perform custom paging in which at the footer of the grid view ,there must be a pager 'pervious/next with numeric'

this is what i did

in aspx page

<asp:GridView ID="TableGridView"  
      
      OnPageIndexChanging="TableGridView_PageIndexChanging"      
      runat="server"  AutoGenerateColumns="False" 
     AllowPaging="True" AllowSorting="True" >
    
 </asp:GridView>
      
        <asp:Button ID="btnConnect" runat="server"  Style="z-index: 113;
            left: 260px; position: absolute; top: 143px" Text="Connect & Populate" OnClick="btnConnect_Click" />

in code behind page

public partial class _Default : System.Web.UI.Page
{
    
    public static DataTable Table = new DataTable();
    ArrayList ParameterArray = new ArrayList();


    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack && (bool)Session["IsConnectionInfoSet"]==true)
            CreateTemplatedGridView();

    }

    protected void TableGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        //CreateTemplatedGridView();
        TableGridView.PageIndex = e.NewPageIndex;
        TableGridView.DataBind();
    }


    protected void btnConnect_Click(object sender, EventArgs e)
    {
        Session["IsConnectionInfoSet"] = true;
        CreateTemplatedGridView();
    }
   
    void PopulateDataTable()
    {
        Table = new DataTable();
        TableGridView.Columns.Clear();
    
        SqlDataAdapter adapter = new SqlDataAdapter("select * from customer", "Data Source=OPWFMS-7KYGZ7SB;Initial Catalog=Mayank;User ID=sa;Password=sa");
            adapter.Fill(Table);
       
    }
    void CreateTemplatedGridView()
    {
        // fill the table which is to bound to the GridView
        PopulateDataTable();
        // add templated fields to the GridView
        TemplateField BtnTmpField = new TemplateField();
        BtnTmpField.ItemTemplate =
            new DynamicallyTemplatedGridViewHandler(ListItemType.Item, "...", "Command");
        BtnTmpField.HeaderTemplate =

            new DynamicallyTemplatedGridViewHandler(ListItemType.EditItem, "...", "Command");
        TableGridView.Columns.Add(BtnTmpField);

        for (int i = 0; i < Table.Columns.Count; i++)
        {
            
            TemplateField ItemTmpField = new TemplateField();
            // create HeaderTemplate
            ItemTmpField.HeaderTemplate = new DynamicallyTemplatedGridViewHandler(ListItemType.Header,
                                                          Table.Columns[i].ColumnName,
                                                          Table.Columns[i].DataType.Name);
            // create ItemTemplate
            ItemTmpField.ItemTemplate = new DynamicallyTemplatedGridViewHandler(ListItemType.Item,
                                                          Table.Columns[i].ColumnName,
                                                          Table.Columns[i].DataType.Name);
            //create EditItemTemplate
            
            // then add to the GridView
            TableGridView.Columns.Add(ItemTmpField);
            
        }

        // bind and display the data
        TableGridView.DataSource = Table;
        TableGridView.DataBind();
    }
   
   
   
}

and in the class file

public class DynamicallyTemplatedGridViewHandler : ITemplate
{

    ListItemType ItemType;
    string FieldName;
    string InfoType;

    public DynamicallyTemplatedGridViewHandler(ListItemType item_type, string field_name, string info_type)
    {
        ItemType = item_type;
        FieldName = field_name;
        InfoType = info_type;
    }

    public void InstantiateIn(System.Web.UI.Control Container)
    {
        switch (ItemType)
        {
            case ListItemType.Header:
                Literal header_ltrl = new Literal();
                header_ltrl.Text = "<b>" + FieldName + "</b>";
                Container.Controls.Add(header_ltrl);
                break;
            case ListItemType.Item:
                switch (InfoType)
                {
                    case "Command":
                        break;

                    default:
                        Label field_lbl = new Label();
                        field_lbl.ID = FieldName;
                        field_lbl.Text = String.Empty; //we will bind it later through 'OnDataBinding' event
                        field_lbl.DataBinding += new EventHandler(OnDataBinding);
                        Container.Controls.Add(field_lbl);
                        break;
                }
                break;        
        }
    }

    private void OnDataBinding(object sender, EventArgs e)
    {

        object bound_value_obj = null;
        Control ctrl = (Control)sender;
        IDataItemContainer data_item_container = (IDataItemContainer)ctrl.NamingContainer;
        bound_value_obj = DataBinder.Eval(data_item_container.DataItem, FieldName);
        switch (ItemType)
        {
            case ListItemType.Item:
                Label field_ltrl = (Label)sender;
                field_ltrl.Text = bound_value_obj.ToString();
                break;     
        }

    }

}

but for my requirements I want to use that code

class NumericWithNext : ITemplate
                    {

                    GridView localGrid;
                    int intSlotNo = 0;

                    #region CONTRUCTOR

                    public NumericWithNext(GridView gv)
                    {
                        localGrid = gv;
                        //intSlotNo = slotNo;
                        intSlotNo = localGrid.PageIndex / 10;

                        //constructor
                    }
      public void InstantiateIn(Control container)
                    {
                    LinkButton prevTenRecords = new LinkButton();
                    prevTenRecords.Text = "Previous 10 Pages";
                    prevTenRecords.CssClass = "PagingLnks";
                    prevTenRecords.CommandArgument = ((intSlotNo - 1) * 10 + 1).ToString(); ;
                    prevTenRecords.CommandName = "Page";
                    //prevTenRecords.Click += new EventHandler(prevTenRecords_Click);
                    prevTenRecords.Width = Unit.Pixel(125);
                    if (intSlotNo > 0)
                    {
                    container.Controls.Add(prevTenRecords);
                    }

                    LinkButton nextTenRecords = new LinkButton();
                    nextTenRecords.Text = "Next 10 Pages";
                    nextTenRecords.CommandName = "Page";
                    nextTenRecords.CommandArgument = ((intSlotNo + 1) * 10 + 1).ToString();
                    // nextTenRecords.Click += new EventHandler(nextTenRecords_Click);
                    nextTenRecords.CssClass = "PagingLnks";
                    nextTenRecords.Width = Unit.Pixel(118);
                    // nextTenRecords.Visible = false;



                    LinkButton prev = new LinkButton();
                    prev.Text = "Previous Page";
                    prev.CssClass = "PagingLnks";
                    prev.CommandArgument = "Prev";
                    prev.CommandName = "Page";
                    prev.Width = Unit.Pixel(90);
                    if (localGrid.PageIndex > 0)
                    {
                    container.Controls.Add(prev);
                    }

                    //for (int pagenum = 1; pagenum <= localGrid.PageCount; pagenum++)
                    for (int pagenum = (intSlotNo*10)+1; pagenum <= (intSlotNo+1)*10; pagenum++)
                    {
                    if (pagenum > localGrid.PageCount)
                    {
                    nextTenRecords.Visible = false;
                    break;
                    }
                    LinkButton pageInd = new LinkButton();
                    if (pagenum == localGrid.PageIndex + 1)
                    {
                    //pageInd.ForeColor = System.Drawing.Color.Green;PagingSelected
                    pageInd.CssClass = "PagingSelected";
                    }
                    else
                    {
                    pageInd.CssClass = "PagingLnks";
                    }
                    pageInd.ID = "PageInd_" + pagenum; 
                    pageInd.Text = pagenum.ToString();
                    pageInd.CommandName = "Page";
                    pageInd.CommandArgument = pagenum.ToString();
                    container.Controls.Add(pageInd);
                    pageInd.Width = Unit.Pixel(10);
                    }

                    LinkButton next = new LinkButton();
                    next.Text = " Next Page";
                    next.CommandName="Page";
                    next.CommandArgument = "Next";
                    next.CssClass = "PagingLnks";
                    next.Width = Unit.Pixel(80);
                    if (localGrid.PageIndex < localGrid.PageCount - 1)
                    {
                    container.Controls.Add(next);
                    }

                    container.Controls.Add(nextTenRecords);
                    }

                    void nextTenRecords_Click(object sender, EventArgs e)
                    {
                    //throw new Exception("The method or operation is not implemented.");
                    intSlotNo++;

                    }

                    void prevTenRecords_Click(object sender, EventArgs e)
                    {
                    //throw new Exception("The method or operation is not implemented.");
                    intSlotNo--;
                    }

plz let me know how can i do that

This article has been dead for over six months. Start a new discussion instead.