473,228 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,228 software developers and data experts.

custom paging using 'next/pre with numeric'

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
Expand|Select|Wrap|Line Numbers
  1.   <asp:GridView ID="TableGridView"  
  3.       OnPageIndexChanging="TableGridView_PageIndexChanging"      
  4.       runat="server"  AutoGenerateColumns="False" 
  5.      AllowPaging="True" AllowSorting="True" >
  7.  </asp:GridView>
  9.         <asp:Button ID="btnConnect" runat="server"  Style="z-index: 113;
  10.             left: 260px; position: absolute; top: 143px" Text="Connect & Populate" OnClick="btnConnect_Click" />
in code behind page
Expand|Select|Wrap|Line Numbers
  1. public partial class _Default : System.Web.UI.Page
  2. {
  4.     public static DataTable Table = new DataTable();
  5.     ArrayList ParameterArray = new ArrayList();
  8.     protected void Page_Load(object sender, EventArgs e)
  9.     {
  10.         if (IsPostBack && (bool)Session["IsConnectionInfoSet"]==true)
  11.             CreateTemplatedGridView();
  13.     }
  15.     protected void TableGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
  16.     {
  17.         //CreateTemplatedGridView();
  18.         TableGridView.PageIndex = e.NewPageIndex;
  19.         TableGridView.DataBind();
  20.     }
  23.     protected void btnConnect_Click(object sender, EventArgs e)
  24.     {
  25.         Session["IsConnectionInfoSet"] = true;
  26.         CreateTemplatedGridView();
  27.     }
  29.     void PopulateDataTable()
  30.     {
  31.         Table = new DataTable();
  32.         TableGridView.Columns.Clear();
  34.         SqlDataAdapter adapter = new SqlDataAdapter("select * from customer", "Data Source=OPWFMS-7KYGZ7SB;Initial Catalog=Mayank;User ID=sa;Password=sa");
  35.             adapter.Fill(Table);
  37.     }
  38.     void CreateTemplatedGridView()
  39.     {
  40.         // fill the table which is to bound to the GridView
  41.         PopulateDataTable();
  42.         // add templated fields to the GridView
  43.         TemplateField BtnTmpField = new TemplateField();
  44.         BtnTmpField.ItemTemplate =
  45.             new DynamicallyTemplatedGridViewHandler(ListItemType.Item, "...", "Command");
  46.         BtnTmpField.HeaderTemplate =
  48.             new DynamicallyTemplatedGridViewHandler(ListItemType.EditItem, "...", "Command");
  49.         TableGridView.Columns.Add(BtnTmpField);
  51.         for (int i = 0; i < Table.Columns.Count; i++)
  52.         {
  54.             TemplateField ItemTmpField = new TemplateField();
  55.             // create HeaderTemplate
  56.             ItemTmpField.HeaderTemplate = new DynamicallyTemplatedGridViewHandler(ListItemType.Header,
  57.                                                           Table.Columns[i].ColumnName,
  58.                                                           Table.Columns[i].DataType.Name);
  59.             // create ItemTemplate
  60.             ItemTmpField.ItemTemplate = new DynamicallyTemplatedGridViewHandler(ListItemType.Item,
  61.                                                           Table.Columns[i].ColumnName,
  62.                                                           Table.Columns[i].DataType.Name);
  63.             //create EditItemTemplate
  65.             // then add to the GridView
  66.             TableGridView.Columns.Add(ItemTmpField);
  68.         }
  70.         // bind and display the data
  71.         TableGridView.DataSource = Table;
  72.         TableGridView.DataBind();
  73.     }  
  74. }
and in the class file
Expand|Select|Wrap|Line Numbers
  1. public class DynamicallyTemplatedGridViewHandler : ITemplate
  2. {
  4.     ListItemType ItemType;
  5.     string FieldName;
  6.     string InfoType;
  8.     public DynamicallyTemplatedGridViewHandler(ListItemType item_type, string field_name, string info_type)
  9.     {
  10.         ItemType = item_type;
  11.         FieldName = field_name;
  12.         InfoType = info_type;
  13.     }
  15.     public void InstantiateIn(System.Web.UI.Control Container)
  16.     {
  17.         switch (ItemType)
  18.         {
  19.             case ListItemType.Header:
  20.                 Literal header_ltrl = new Literal();
  21.                 header_ltrl.Text = "<b>" + FieldName + "</b>";
  22.                 Container.Controls.Add(header_ltrl);
  23.                 break;
  24.             case ListItemType.Item:
  25.                 switch (InfoType)
  26.                 {
  27.                     case "Command":
  28.                         break;
  30.                     default:
  31.                         Label field_lbl = new Label();
  32.                         field_lbl.ID = FieldName;
  33.                         field_lbl.Text = String.Empty; //we will bind it later through 'OnDataBinding' event
  34.                         field_lbl.DataBinding += new EventHandler(OnDataBinding);
  35.                         Container.Controls.Add(field_lbl);
  36.                         break;
  37.                 }
  38.                 break;        
  39.         }
  40.     }
  42.     private void OnDataBinding(object sender, EventArgs e)
  43.     {
  45.         object bound_value_obj = null;
  46.         Control ctrl = (Control)sender;
  47.         IDataItemContainer data_item_container = (IDataItemContainer)ctrl.NamingContainer;
  48.         bound_value_obj = DataBinder.Eval(data_item_container.DataItem, FieldName);
  49.         switch (ItemType)
  50.         {
  51.             case ListItemType.Item:
  52.                 Label field_ltrl = (Label)sender;
  53.                 field_ltrl.Text = bound_value_obj.ToString();
  54.                 break;     
  55.         }
  57.     }
  59. }
but for my requirements I want to use that code
Expand|Select|Wrap|Line Numbers
  1.    class NumericWithNext : ITemplate
  2.                     {
  4.                     GridView localGrid;
  5.                     int intSlotNo = 0;
  7.                     #region CONTRUCTOR
  9.                     public NumericWithNext(GridView gv)
  10.                     {
  11.                         localGrid = gv;
  12.                         //intSlotNo = slotNo;
  13.                         intSlotNo = localGrid.PageIndex / 10;
  15.                         //constructor
  16.                     }
  17.       public void InstantiateIn(Control container)
  18.                     {
  19.                     LinkButton prevTenRecords = new LinkButton();
  20.                     prevTenRecords.Text = "Previous 10 Pages";
  21.                     prevTenRecords.CssClass = "PagingLnks";
  22.                     prevTenRecords.CommandArgument = ((intSlotNo - 1) * 10 + 1).ToString(); ;
  23.                     prevTenRecords.CommandName = "Page";
  24.                     //prevTenRecords.Click += new EventHandler(prevTenRecords_Click);
  25.                     prevTenRecords.Width = Unit.Pixel(125);
  26.                     if (intSlotNo > 0)
  27.                     {
  28.                     container.Controls.Add(prevTenRecords);
  29.                     }
  31.                     LinkButton nextTenRecords = new LinkButton();
  32.                     nextTenRecords.Text = "Next 10 Pages";
  33.                     nextTenRecords.CommandName = "Page";
  34.                     nextTenRecords.CommandArgument = ((intSlotNo + 1) * 10 + 1).ToString();
  35.                     // nextTenRecords.Click += new EventHandler(nextTenRecords_Click);
  36.                     nextTenRecords.CssClass = "PagingLnks";
  37.                     nextTenRecords.Width = Unit.Pixel(118);
  38.                     // nextTenRecords.Visible = false;
  42.                     LinkButton prev = new LinkButton();
  43.                     prev.Text = "Previous Page";
  44.                     prev.CssClass = "PagingLnks";
  45.                     prev.CommandArgument = "Prev";
  46.                     prev.CommandName = "Page";
  47.                     prev.Width = Unit.Pixel(90);
  48.                     if (localGrid.PageIndex > 0)
  49.                     {
  50.                     container.Controls.Add(prev);
  51.                     }
  53.                     //for (int pagenum = 1; pagenum <= localGrid.PageCount; pagenum++)
  54.                     for (int pagenum = (intSlotNo*10)+1; pagenum <= (intSlotNo+1)*10; pagenum++)
  55.                     {
  56.                     if (pagenum > localGrid.PageCount)
  57.                     {
  58.                     nextTenRecords.Visible = false;
  59.                     break;
  60.                     }
  61.                     LinkButton pageInd = new LinkButton();
  62.                     if (pagenum == localGrid.PageIndex + 1)
  63.                     {
  64.                     //pageInd.ForeColor = System.Drawing.Color.Green;PagingSelected
  65.                     pageInd.CssClass = "PagingSelected";
  66.                     }
  67.                     else
  68.                     {
  69.                     pageInd.CssClass = "PagingLnks";
  70.                     }
  71.                     pageInd.ID = "PageInd_" + pagenum; 
  72.                     pageInd.Text = pagenum.ToString();
  73.                     pageInd.CommandName = "Page";
  74.                     pageInd.CommandArgument = pagenum.ToString();
  75.                     container.Controls.Add(pageInd);
  76.                     pageInd.Width = Unit.Pixel(10);
  77.                     }
  79.                     LinkButton next = new LinkButton();
  80.                     next.Text = " Next Page";
  81.                     next.CommandName="Page";
  82.                     next.CommandArgument = "Next";
  83.                     next.CssClass = "PagingLnks";
  84.                     next.Width = Unit.Pixel(80);
  85.                     if (localGrid.PageIndex < localGrid.PageCount - 1)
  86.                     {
  87.                     container.Controls.Add(next);
  88.                     }
  90.                     container.Controls.Add(nextTenRecords);
  91.                     }
  93.                     void nextTenRecords_Click(object sender, EventArgs e)
  94.                     {
  95.                     //throw new Exception("The method or operation is not implemented.");
  96.                     intSlotNo++;
  98.                     }
  100.                     void prevTenRecords_Click(object sender, EventArgs e)
  101.                     {
  102.                     //throw new Exception("The method or operation is not implemented.");
  103.                     intSlotNo--;
  104.                     }

plz let me know how can i do that
Jul 10 '09 #1
16 3953
9,735 Expert Mod 8TB
You realize that this functionality is already part of the GridView right?
In fact it looks like were already using this functionality because you have a method that is actually handling it...

I'm not really sure where you're having problems.
You have a lot of code posted and it's very hard to read through the code and understand what the problem is because you haven't clearly defined what the problem is.

You have 2 classes posted.
Are you trying to use one class instead of the other?
What problems are you having when you try this?

Jul 13 '09 #2
thnks for reply

just copy paste the code so then u come to know what I am trying to do

actually i just want to use class NumericWithNext : ITemplate in my project ,but i am not able to do it .In short I just want to use both of the class but i a not able to do it
Jul 13 '09 #3
9,735 Expert Mod 8TB
I think I know what you want to do here.

You want to combine the two classes into 1 class.

Since you just want to display the paging template in the footer, you should be able to use the DataControlRowType to determine what controls to create.

You'll have to add a parameter to the constructor that accepts the DataControlRowType. Then in the InstantiateIn method you'll check this to determine whether generate the data content template or the footer template.

For example:
Expand|Select|Wrap|Line Numbers
  1. public class DynamicallyTemplatedGridViewHandler : ITemplate
  2. {
  4.     ListItemType ItemType;
  5.     string FieldName;
  6.     string InfoType;
  9.     DataControlRowType templateType;
  11.     public DynamicallyTemplatedGridViewHandler(DataControlRowType template_type, ListItemType item_type, string field_name, string info_type)
  12.     {
  13.         ItemType = item_type;
  14.         FieldName = field_name;
  15.         InfoType = info_type;
  19.         templateType = template_type;
  20.     }
  22. public void InstantiateIn(System.Web.UI.Control Container)
  23. {
  24.         switch (templateType )
  25.         {
  26.             case DataControlRowType.Footer: 
  27. //Do your footer logic stuff here
  28.             break;
  30.            case DataControlRowType.Header:
  31. ///Do your header logic stuff here
  32.             break;
  34.             case DataControlRowType.DataRow;
  35. //Do your data row logic stuff here
  36.             break;
  37.           }
  38. }
Jul 13 '09 #4
hi Frinavale
thanks for reply ,i tried to do that according to you but I am still facing problems becoz if i use that class as footer there are mismatching of public void InstantiateIn() function becoz both have different parameters

if u can do it ,plz do it as i m very much needed of it
Jul 15 '09 #5
9,735 Expert Mod 8TB
When you change the signature of a function (the parameters it takes) then you have to modify all of the code that is calling it.

Therefore, if you modify the constructor method for the DynamicallyTemplatedGridViewHandler class you'll have to change any code that calls it.

You cannot change the signature of the InstantiateIn() method. The reason is because this method is used to implement the ITemplate interface requirements. The ITemplate interface requires that the InstantiateIn method that takes no parameters. Have you never worked with an interface before?

You should be modifying the constructor's parameters...
Jul 15 '09 #6
thnks for reply

I never worked with interface before ,so I am having lot of problems.
I know i have to use constructer according to parameter but how ,as coding depands on parameter ,if I will do any change in parameter code won't work
Jul 15 '09 #7
9,735 Expert Mod 8TB
An interface only contains the signatures of methods, delegates or events for a class. The implementation (the code) is done in the class that Implements the interface.

So, say you have an interface looks like:
Expand|Select|Wrap|Line Numbers
  1. interface MyInterface
  2. {
  3.     void SomeMethod();
  4.     int SomeOtherMethod(int a, int b);
  5. }
If your class implements MyInterface it must supply code for the SomeMethod, and SomeOtherMethod method. The methods that supply the code for the methods defined in the interface must have matching signatures.

If you take a look at the ITemplate interface you will note that it defines 1 method; the InstantiateIn() method. This method takes 1 parameter: A Control object to contain the instances of controls from the inline template.

You can't change the number of parameters for the InstantiateIn method because your are using it to implement (provide code for) the InstantiateIn method defined in the ITemplate interface.

Because of this you're going to have to use the constructor to pass in the data necessary to determine whether your ITemplate class is being used for displaying a header, the data, or a footer....or other.

Please take a look at the code I posted previously....I added a private member that is used for this purpose. This member is initialized in the constructor. It is used in the InstantiateIn method to determine what controls to create.

Jul 15 '09 #8
i just copy paste the classes is code written by you , But I am having lot of errors
Jul 15 '09 #9
9,735 Expert Mod 8TB
I'm sorry but I don't use C# very often.

The code I posted was meant as a guideline for you...it's probably going to have many errors in it. (especially since I start a class and don't have a closing brace "}" to end it)

I could post a working example of what I have but it's in VB and I think you're probably going to have a hard time understanding it.
Jul 15 '09 #10
ya no prb ,thnks anyway for keep checking my posts
plz let me know if u have some other solution
Jul 15 '09 #11
9,735 Expert Mod 8TB
What do you mean "let me know if u have some other solution"?
Are you abandoning this one?

I hope not because you're on the right track...
Jul 15 '09 #12
no no,I am not abandoning this one as i am not good in interfaces so looking for other possible solution
Jul 15 '09 #13
9,735 Expert Mod 8TB
There's nothing very complicated about interfaces.

They are like...hmm... a blue print.

They outline what has to be done and then you do it. Just like a blue print for a house outlines what has to be done and the people building it use this to create a house.

What's neat about interfaces is it lets you create a class that other classes already know how to use.


Because the interface defines methods that are supposed to do some task. Since these method are always going to have the same result, other classes (like the GridView) can use your class, and call the defined methods to get the desired result.

Let's take a look at the ITemplate interface.

It defines the InstantiateIn method...

According to MSDN, the task of this method is as follows: "The InstantiateIn method defines the Control object that child controls and templates belong to."

In other words, when you add code for this, you specify what controls are needed to create a template used to display your data.

You will add the controls that you need to create template for your data, and someone else implementing the ITemplate interface will supply other controls that they need to create a template for their data.

The GridView control is able to use your class or the other persons class because it knows that the InstantiateIn method will define the appropriate template to display the data.

Does this make sense?
Jul 15 '09 #14
ya,definately it makes sense
Jul 15 '09 #15
9,735 Expert Mod 8TB
Good :)

Let's take a look at what you have right now....
Jul 15 '09 #16
9,735 Expert Mod 8TB
Right now you're using a ListItemType to define what your Template should look like; but, there's something better suited for this... the DataControlRowType.

The reason it's better suited is because it specifies the function of a row in a data control, such as a DetailsView or GridView control.

The ListItemType specifies the type of an item in a list control.

So the first change you should make to your DynamicallyTemplatedGridViewHandler class is to use the DataControlRowType instead of the ListItemType.

Why don't we start with something simple and work our way up?
I don't have your database, don't know what your data looks like or how it you want it to be formatted. So I think working with a simpler example project might be easier for both of us.
Jul 15 '09 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Alex | last post by:
I created a page to show RealEstate Data with images retrived from the MSSQL 2000. I am using a DataGrid control: <asp:datagrid AllowPaging="True" OnPageIndexChanged="Pageindexchanged" > ...
by: Stephen | last post by:
This is a real brain-teaser and i'd really appreciate it if someone can try and understand what im trying to do and give me a few pointers or ideas to help me work out my problem. Im basically...
by: Clint | last post by:
Hi, I am trying to implement the custom paging in the datalist in this format: << Prev 1,2,3,4,5 Next >>. Does anyone knows how to do this. Thanks in advance. Clint
by: Raed Sawalha | last post by:
I have aspx page with user control , in the user control i have DataGrid with custom paging the grid is displaying contents of datatable as following schema <xs:element name="id"...
by: thechaosengine | last post by:
Hi all, Can somebody tell me if the built in paging support for the datagrid works when using a custom collection and a custom business object as the data. I was well pleased when I found that...
by: asad | last post by:
hello friends, how ru all I want to create a custom paging logic in ASP.NET with a next link for example if i have 100 pages record so i want to show 6 pages link on page one and next link ...
by: Sjaakie | last post by:
Hi all, I have a Usercontrol containing a pre-formatted DataGrid and some code which by default enables paging (with links 1..20). I now want to add some extra paging information to the...
by: Edwin Knoppert | last post by:
I simply want to insert a word before the numerics for paging.. *If* i need to manage this true a template then how to keep the numeric stuff? I was only able to prepare buttons which do adding...
by: richard | last post by:
OK, Im finished pulling my hair out and now I need help. I have created a VB class file for my custom paging, in it I create a table with 2 rows, in the rows I have linkbuttons for first page,...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.