473,836 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

custom paging using 'next/pre with numeric'

18 New Member
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"  
  2.  
  3.       OnPageIndexChanging="TableGridView_PageIndexChanging"      
  4.       runat="server"  AutoGenerateColumns="False" 
  5.      AllowPaging="True" AllowSorting="True" >
  6.  
  7.  </asp:GridView>
  8.  
  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. {
  3.  
  4.     public static DataTable Table = new DataTable();
  5.     ArrayList ParameterArray = new ArrayList();
  6.  
  7.  
  8.     protected void Page_Load(object sender, EventArgs e)
  9.     {
  10.         if (IsPostBack && (bool)Session["IsConnectionInfoSet"]==true)
  11.             CreateTemplatedGridView();
  12.  
  13.     }
  14.  
  15.     protected void TableGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
  16.     {
  17.         //CreateTemplatedGridView();
  18.         TableGridView.PageIndex = e.NewPageIndex;
  19.         TableGridView.DataBind();
  20.     }
  21.  
  22.  
  23.     protected void btnConnect_Click(object sender, EventArgs e)
  24.     {
  25.         Session["IsConnectionInfoSet"] = true;
  26.         CreateTemplatedGridView();
  27.     }
  28.  
  29.     void PopulateDataTable()
  30.     {
  31.         Table = new DataTable();
  32.         TableGridView.Columns.Clear();
  33.  
  34.         SqlDataAdapter adapter = new SqlDataAdapter("select * from customer", "Data Source=OPWFMS-7KYGZ7SB;Initial Catalog=Mayank;User ID=sa;Password=sa");
  35.             adapter.Fill(Table);
  36.  
  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 =
  47.  
  48.             new DynamicallyTemplatedGridViewHandler(ListItemType.EditItem, "...", "Command");
  49.         TableGridView.Columns.Add(BtnTmpField);
  50.  
  51.         for (int i = 0; i < Table.Columns.Count; i++)
  52.         {
  53.  
  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
  64.  
  65.             // then add to the GridView
  66.             TableGridView.Columns.Add(ItemTmpField);
  67.  
  68.         }
  69.  
  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. {
  3.  
  4.     ListItemType ItemType;
  5.     string FieldName;
  6.     string InfoType;
  7.  
  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.     }
  14.  
  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;
  29.  
  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.     }
  41.  
  42.     private void OnDataBinding(object sender, EventArgs e)
  43.     {
  44.  
  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.         }
  56.  
  57.     }
  58.  
  59. }
but for my requirements I want to use that code
Expand|Select|Wrap|Line Numbers
  1.    class NumericWithNext : ITemplate
  2.                     {
  3.  
  4.                     GridView localGrid;
  5.                     int intSlotNo = 0;
  6.  
  7.                     #region CONTRUCTOR
  8.  
  9.                     public NumericWithNext(GridView gv)
  10.                     {
  11.                         localGrid = gv;
  12.                         //intSlotNo = slotNo;
  13.                         intSlotNo = localGrid.PageIndex / 10;
  14.  
  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.                     }
  30.  
  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;
  39.  
  40.  
  41.  
  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.                     }
  52.  
  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.                     }
  78.  
  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.                     }
  89.  
  90.                     container.Controls.Add(nextTenRecords);
  91.                     }
  92.  
  93.                     void nextTenRecords_Click(object sender, EventArgs e)
  94.                     {
  95.                     //throw new Exception("The method or operation is not implemented.");
  96.                     intSlotNo++;
  97.  
  98.                     }
  99.  
  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 4021
Frinavale
9,735 Recognized Expert Moderator Expert
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?

-Frinny
Jul 13 '09 #2
pupilstuff
18 New Member
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
Frinavale
9,735 Recognized Expert Moderator Expert
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 DataControlRowT ype to determine what controls to create.


You'll have to add a parameter to the constructor that accepts the DataControlRowT ype. 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. {
  3.  
  4.     ListItemType ItemType;
  5.     string FieldName;
  6.     string InfoType;
  7.  
  8.  
  9.     DataControlRowType templateType;
  10.  
  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;
  16.  
  17.  
  18.  
  19.         templateType = template_type;
  20.     }
  21.  
  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;
  29.  
  30.            case DataControlRowType.Header:
  31. ///Do your header logic stuff here
  32.             break;
  33.  
  34.             case DataControlRowType.DataRow;
  35. //Do your data row logic stuff here
  36.             break;
  37.           }
  38. }
Jul 13 '09 #4
pupilstuff
18 New Member
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
Frinavale
9,735 Recognized Expert Moderator Expert
@pupilstuff
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 DynamicallyTemp latedGridViewHa ndler 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
pupilstuff
18 New Member
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
Frinavale
9,735 Recognized Expert Moderator Expert
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.

-Frinny
Jul 15 '09 #8
pupilstuff
18 New Member
i just copy paste the classes is code written by you , But I am having lot of errors
Jul 15 '09 #9
Frinavale
9,735 Recognized Expert Moderator Expert
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

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

Similar topics

1
4447
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" > Sub PageIndexChanged(ByVal sende.........)
0
1630
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 using the example of CUSTOM PAGING on a DataGrid on this page: http://www.dotnetjunkies.com/Tutorial/EA868776-D71E-448A-BC23-B64B871F967F.dcik and im trying to add extra functionality in the DataGrid Paging - Custom Paging example. I'm able to get...
3
5064
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
0
1256
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" type="xs:string" minOccurs="0" /> <xs:element name="size" type="xs:int" minOccurs="0" /> <xs:element name="filesize" type="xs:long" minOccurs="0" /> <xs:element name="date" type="xs:dateTime" minOccurs="0" /> <xs:element name="sendername" type="xs:string"...
1
1644
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 I could bind a custom class to the datagrid. Now however, I'm worried that paging is buggered because I'm using custom classes. Should this be possible and if not, would custom paging work?
2
1793
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 like that 1 2 3 4 5 6 <Next>
0
1002
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 PagerTemplate using the code below. It does show me all the labels and links, but the event I attach to the previous and next links isn't triggered on click. I must be doing something wrong, perhaps you can help me out? TIA
1
1808
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 and subtracting, i want the numerics. ?
0
1403
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, previous page, next page and last page. The buttoms are created like: CODE 'configure the link buttons link_1.ID = "f_link" link_2.ID = "p_link"
0
9671
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10852
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10553
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10596
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10255
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6980
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4021
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.