Question

Custom Paging datagrid

Asked by: CVSmarc

Hi all
I know that i am asking for this in .net 1.1 and datagrids, but unfortunately i have to work with a legacy system here instead of 2.0.

Now what i have created a CustomDataGrid class which Inherits System.Web.UI.Page. Within this class i am wanting it to deal with two things one bi-directional sorting and custom paging. The idea behind creating this class is that i can use my new CustomDataGrid and it will automatically have the given requirement and i don’t have to go around and include half a dozen additional controls to provide the additional functionality.

I have got the sorting working alright, but i am having a bit of trouble with the paging. I have spent a lot of time looking at different tutorials and stuff on the web but they all seem to miss the big picture.
    - The pager needs to be in the following format (were 6 is the current page)    
       First Prev 4 5 6 7 8 Next Last of 45
    - ALL of this items in the pager to link thought to the appropriate page (not  
      just the  First/Prev/Next/Last links)
    - I need this pager to be in the footer of the datagrid (again looking around
      on the web, i couldn't find a datagrid that has a custom pager in the footer
      of the datagrid)
    - If the pager can be put into the footer i need it on the right and 'Record x -
      y of z'  on the right and the pager on the left (note i already can get all
      of the information about what page i am on and how many records
      there are in total and can derive the rest)

Now i tried to have a go at this but kept running into a few brick walls (i might be wrong though, i'm still working my way through .net so please help me out if i making a big mistake)
     - because these pager items need to run events when they are clicked
       i can't just build up the formatted HTML
     - because i don’t want to include any additional controls on the each page
       that i use this new class in, i have to dynamically build up the controls
       and place them
     - because i am dynamically building up the controls, i need to dynamically
       bind events to these controls
     - because they are dynamically added controls it makes it harder to add the
       html formatting that i need to the pager (i.e. '<div class="navPagging">
       <img src="image/buttonfirst.jpg" border="0"><img src="image/buttonprev.jpg"
        border="0"><div>&nbsp; 3 4 <span class="selected">5</span> 6 7 &nbsp;
       </div><img src="image/buttonnext.jpg"><img src="image/buttonlast.jpg">
       <div>&nbsp; of 34</div></div>', just pretend that it has the href tags were
       they would need to go)
     - because of the nested design of the pager and because of the dynamic creation
       of each of the controls i would need to a few nested placeholders and the controls
       being added at the relevant places

Thus, when looking at this method and the problems I was running into I thought that there must be an easer way of doing what i need to do. So i decided to ask some people smarter than me.
Thanks ant

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-04-15 at 00:20:11ID21814842
Tags

datagrid

,

paging

Topic

Programming for ASP.NET

Participating Experts
3
Points
0
Comments
17

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Problem: Datagrid pager with Arraylist bound to it
    Hello, I have a problem with my datagrid pager function. It currently is able to page forward ">" through the datagrid but when I click on the previous "<" button, the "<" button is unclickable anymore (ie. I can't page backwards anymor...
  2. datagrid
    Is there anyway to change the style of the index page of the datagrid on runtime without custom paging. There should be a way of doing that like making the current page index bold on change of the page.I see that on most sites ,are they custom grids or can it be done on our d...
  3. Datagrid pager - appeding text in front of the pager
    I am using the default datagrid paging. I want to apprend the text "Page: " in front of the numeric paging elements. This will make it more clear as to what those numbers are for. Is there any easy fix for this? thanks

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: asdaveyPosted on 2006-04-15 at 04:11:53ID: 16459920

Hmmm.

I make this comment fully aware of not knowing exactly what situations you've tried and what design tradeoff decisions you've already made.

I would strongly encourage you to try and implement your solution using a UserControl. Tonight I'm actually working on a very similar control (but in .Net 2 which has the GridView which is very easy to work with). By using a UserControl, you can create a composite control. Basically you'd be hooking up your custom rendered pager with .Net 1.1's DataGrid control.

In the UserControl (let's call it DataGridEx) the markup could look something like:

<div>
  <asp:datagrid runat="server" id="datagrid" autogeneratecolumns="true"/>
  <asp:placeholder runat="server" id="pager"/>
</div>

In your DataGridEx's PreRender method, you could determine what links to pages you'd like to display (eg First, Prev, 2, 3, 4 .... etc) and add them as LinkButton's to the placeholder control 'pager'. Hook up the events and you are away.

On the page that you would like to have your DataGridEx appear, the page would look like:

<%@ Register TagPrefix="MyUserControls" TagName="DataGridEx" src="~/usercontrols/datagridex.ascx" %>

<myusercontrols:datagridex runat="server"/>

If you've not had any previous experience with UserControls I'd suggest tackling something a little simpler for your first attemp (a login page or something).

If you've already looked down this path and have made the decision that a Server control is the way that you have to go, I'd suggest inhieriting from WebControl instead of Page since the Page control is very much targetted to rendering pages and not controls.

HIH

Andy

 

by: CVSmarcPosted on 2006-04-15 at 05:38:46ID: 16460204

Thanks a lot for your reply.

Ok the biggest problem i have with what you are suggesting is the "In your DataGridEx's PreRender method, you could determine what links to pages you'd like to display (eg First, Prev, 2, 3, 4 .... etc) and add them as LinkButton's to the placeholder control 'pager'. Hook up the events and you are away.".

As per your suggestion i have put together the below sub which should be able to handles the construction of the paging.
 
        Protected Sub CreatePaging(ByVal objPlaceHolder As PlaceHolder)
            Dim PagerFirstImg As New HyperLink
            Dim PagerLastImg As New HyperLink
            Dim PagerPreviousImg As New HyperLink
            Dim PagerNextImg As New HyperLink

            Dim PagerNumberPosA As New HyperLink
            Dim PagerNumberPosB As New HyperLink
            Dim PagerNumberPosC As New HyperLink
            Dim PagerNumberPosD As New HyperLink
            Dim PagerNumberPosE As New HyperLink

            If _intPageCurrentPage > 0 Then
                'Adds the first image
                PagerFirstImg.ImageUrl = objPlaceHolder.ResolveUrl("~/image/buttonfirst.jpg")
               .....  'Event code needs to be added in here
                'Adds the prvious image
                PagerPreviousImg.ImageUrl = objPlaceHolder.ResolveUrl("~/image/buttonprev.jpg")
               .....  'Event code needs to be added in here
            End If
 
            If _intPageRecordEnd < _intPageTotalRecordCount Then
                'Adds the first image
                PagerNextImg.ImageUrl = objPlaceHolder.ResolveUrl("~/image/buttonnext.jpg")
               .....  'Event code needs to be added in here
                'Adds the prvious image
                PagerLastImg.ImageUrl = objPlaceHolder.ResolveUrl("~/image/buttonlast.jpg")
               .....  'Event code needs to be added in here
            End If

           .......................      'Code to constuct the PagerNumberPosX controls

            'Sets it to the place holder
            .......................    'Add in the additional HTML and Bind all the controls the the placeholder
        End Sub


Now i am pretty sure that i can hook up the events and can write the code to construct the PagerNumberPosX control, the only problem i have at the moment is how to add in my formatting HTML. The HTML that is constructed for each of the controls should be something like the following:
       PagerFirstImg - <a href="javascript:...."><img src="image/buttonfirst.jpg" border="0"></a>
       PagerPreviousImg - <a href="javascript:...."><img src="image/buttonprev.jpg" border="0"></a>
       PagerNumberPosA - <a href="javascript:....">3</a>
       PagerNumberPosB - <a href="javascript:....">4</a>
       PagerNumberPosC - <a href="javascript:....">5</a>
       PagerNumberPosD - <a hef="javascript:.....">6</a>
       PagerNumberPosE - <a href="javascript:....">7</a>
       PagerNextImg - <a href="javascript:...."><img src="image/buttonnext.jpg"></a>
       PagerLastImg - <a href="javascript:...."><img src="image/buttonlast.jpg"></a>

I need to turn it into to something like this (with the added href offcourse):
       <div class="navPagging"><img src="image/buttonfirst.jpg" border="0">
       <img src="image/buttonprev.jpg" border="0"><div>&nbsp; 3 4
       <span class="selected">5</span> 6 7 &nbsp;</div><img src="image/buttonnext.jpg">
       <img src="image/buttonlast.jpg"><div>&nbsp; of 34</div></div>

Now if i understand the '.Controls.Add(....)' can't just plain HTML inserted into it. So i need a what of binding the objects all together, with the necessary HTML and i really dont want to go about it by creating a whole heap of nested PlaceHolder's.

Lastly i am just wondering why you would suggest creating a user control over a CustomDataGrid class? It's just that atm i am not bound to using a class, but i just thought that using a class would give me more functionality.

Thanks
ant

 

by: asdaveyPosted on 2006-04-16 at 16:47:39ID: 16466267

Ant,

With regards to formatting your pager, a lot of what you are trying to do can be best acheived through a combination of code behind and controls embeeded in the .ascx page (some people refer to this as the designer source).

Your DataGridEx.ascx could look something like this:

<div>
  <asp:datagrid runat="server" id="datagrid" allowpaging="true" pagerstyle-visibile="false"/>
  <div class="navpaging">
    <asp:imagebutton runat="server" id="first" imageurl="~/image/buttonfirst.jpg" oncommand="PageNavigation" commandaname="First"/>
    <asp:imagebutton runat="server"  id="prev" imageurl="~/image/buttonprev.jpg" oncommand="PageNavigation" commandname="Prev"/>
   
    <asp:placeholder runat="server" id="pageNumbersPlaceHolder"/>

    <asp:imagebutton runat="server" id="next" imageurl="~/image/buttonnext.jpg" oncommand="PageNavigation" commandaname="Next"/>
    <asp:imagebutton runat="server"  id="last" imageurl="~/image/buttonlast.jpg" oncommand="PageNavigation" commandname="Last"/>

  </div>
</div>

The above has taken care of rendering our image buttons and has given us a nice easy way to add the numbers that link to the various pages. So, in Page_PreRender you could have some code that looks like this (you will have to forgive my vb.net ... its a little rusty):

Page_PreRender(sender as Object, e as EventArgs)

  Dim totalPageCount as Integer = datagrid.pagecount
  Dim currentPage as Integer = datagrid.currentpageindex + 1
 
  '
  ' Assuming that we want to display the page numbers of say 2 either side of our current page number
  '

  If (currentPage <= 2) Then
    ' Exercise for ant to complete
  Else if (currentPage >= totalPageCount - 2) Then
    ' Execise for ant to complete
  Else

    Dim pageNumbers as New LiteralControl()

    pageNumbers.Text = string.Format("&nbsp;{0}&nbsp;{1}&nbsp;<span style='font-weight:bold;'>{2}</span>&nbsp;{3}&nbsp;{4}", currentPage - 2, currentPage - 1, currentPage, currentPage + 1, currentPage + 2)

    pageNumbersPlaceHolder.Controls.Add(pageNumbers)

  End If

End Sub

And if you are wondering about the OnCommand event handler for the image buttons it could look something like this:

      Protected Sub PageNavigation(ByVal sender As Object, ByVal e As CommandEventArgs)

            Select Case (e.CommandName)
                  Case "First"
                        datagrid.CurrentPageIndex = 0

                  Case "Prev"
                        datagrid.CurrentPageIndex = datagrid.CurrentPageIndex - 1

                  Case "Next"
                        datagrid.CurrentPageIndex = datagrid.CurrentPageIndex + 1

                  Case "Last"
                        datagrid.CurrentPageIndex = datagrid.PageCount - 1

            End Select

      End Sub

You asked why I suggest the user control over writing your own. I find that user controls are fantastic for writing composite controls (controls that combine the behaviour of one or more controls into a single package). What makes them so good is the ability to leverage the power of existing controls and customise their behaviour quickly. You are correct in saying that a class will give you more functionality, and sometimes that is the only answer. But for this particular problem, a UserControl can be implemented 10 times faster than implementing your own control from scratch.

HIH

Andy

 

by: CVSmarcPosted on 2006-04-16 at 17:03:46ID: 16466306

Thanks allot for your comments.
This is starting to make a bit more sense now. Just one other thing... If i wanted to make it possible for the user to select the one of the two numbers on either side of the current page and actually go to that page, how would i go about going that.
ant

 

by: CVSmarcPosted on 2006-04-16 at 17:11:08ID: 16466318

Also would it be possible to have one placeholder and have all the imagebutton controls and the page numbers put into that one placeholder or does that bring be back to the same place i was to start (having to create all the controls by hand, binding the events and then adding them all together)??

 

by: acperkinsPosted on 2006-04-16 at 18:38:36ID: 16466573

It is a violation of the Membership Agreement to have more than 500 points per question.  Please delete the folllowing question, before someone contributes:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21815455.html

Alternatively, post a message in Community Support to have it converted to a "pointer" question for 20 points.

Also, the following questions are considered abandoned, please attend to them:
1 03/16/2006 500 HTML - PDF Generation  Open Active Server Pages (ASP)
2 01/31/2006 500 Detect difference between single click a...  Open JavaScript

 

by: asdaveyPosted on 2006-04-16 at 18:49:32ID: 16466596

To make it possible to select a link on both sides of the displayed page index you could use two HyperLink controls on either side. Set thier CommandName to "Go", their CommandArgument to the page number you want to navigate to and their OnCommand event handler to PageNavigation.

Then in the PageNaviagition add a new Case like so:

  Case "Go":
    datagrid.CurrentPageIndex = Integer.Parse(e.CommandArgs)

As for your comment regarding hosting all of the navigation controls into a single PlaceHolder, yeah that will mean that you will have to go back to rendering all of that HTML by hand. However, maybe what you want to do is host them all in an asp:Panel control.

 

by: asdaveyPosted on 2006-04-16 at 18:50:50ID: 16466599

Before when I said HyperLink control I meant LinkButton. Any control can be used, but it would be better to use one that gives you the look you want and supports the OnCommand event.

 

by: CVSmarcPosted on 2006-04-16 at 20:01:58ID: 16466830

Thanks for the reply.

One thing i am trying to do is something along this line...
                For i = intPagerStartPos To intPagerEndPos
                    strPagerHTML = strPagerHTML & "<a href=""javascript:ChangePage(" & i.ToString() & ")"">" & i & "</a> "
                Next

and then have this

            function ChangePage(intPage) {
                //Save the page number clicked to the hidden field
                document.getElementById("PageNumber").value = intPage;
                //Calls the __doPostBack function to post back the form and execute the PageClick event
                __doPostBack('PageIndexChanged','');
            }

But i seem to be having some trouble with .net detecting that it needs to run the PageIndexChanged event/function. Got any ideas?

If i can get this to work, is it a reasonable way of going about this or not real? I am keen to come up with a solution that require the use of only one placeholder and all the different buttons/items/links be placed inside it. That way all i need to go is have the one control on each page and if i decide to change the pager it should make things easer. The only thing i am worried about is that if i go with this approach i have to have a method that creates the additional webcontrols for each item, add the handers for each of those items and then bind them all together and include the formatting HTML. From what i have seen there doesn't seem to be a 'functional' way of doing this (by functional i don’t mean using functions i just mean the overall process is not functional).

Thanks
ant

 

by: asdaveyPosted on 2006-04-16 at 20:25:58ID: 16466885

To be honest I've never handcoded javascript calling back to the server side like that before so I'm little help to you on that side of things, except to say that I would be surprised if using a smattering of server side controls would be more difficult to implement and maintain than using the client rendered javascript approach. The beauty of the server side controls approach is it just works.

 

by: CVSmarcPosted on 2006-04-16 at 20:54:14ID: 16466941

Ok. If you believe that going down server side controls track is the better way to go could you please explain to be how i can go about doing it.

As i have said in the above, the reason why i am hesitant to go down this track in because i want what ever solution i have to only use 1 placeholder and as such unless i am mistaken this means that i have to dynamically create and add the other 10 (note this could change depending on how many pages at once a developer wishes to use and if i have to use any more for formatting) or so server side controls. If i am correct here it then means i have to dynamically add events to all of these as well. Also no one has explained to me yet how i can do all of that and include the additional HTML formatting i need.

If you could answer me this i would be most appreciative. As you can see, if this is the approach i need/should to go down (because i am still learning) why i am hesitant to do it and think that there must be an easer way, whilst still keeping the 1 placeholder (or if you know a way to append to controls to the bottom of the datagrid event be, that way i wouldn't need even a placeholder). My am is for me to be able to use this 'customDataGrid' that i have created and automatically include all the additional function and features that i need.

Thanks
ant

 

by: asdaveyPosted on 2006-04-16 at 21:25:18ID: 16467033

If you want the developer to be able to specify how many page numbers are displayed in between the prev and next commands then that changes things a little.

The reason being is we don't want to be generating controls on the fly if we wan't to be able to handle their events. It can be done, but its what I would consider an advanced technique (you need to fully understand how .Net "magically" wires up javascript events with server side events, and then make sure that all controls that could potentially be the target of an event be created before the LoadViewState method completes).

So you have two options. Use the javascript method that you were talking about earlier (which may work...I just haven't seen any code that does it like that)

OR you could put a theoretical limit on the number of page numbers that will be displayed as links. Say you choose 5. You then have in your ascx page the following:
  <div class="navpaging">
    <asp:imagebutton runat="server" id="first" imageurl="~/image/buttonfirst.jpg" oncommand="PageNavigation" commandaname="First"/>
    <asp:imagebutton runat="server"  id="prev" imageurl="~/image/buttonprev.jpg" oncommand="PageNavigation" commandname="Prev"/>
   
    <asp:linkbutton runat="server" id="navLink1" oncommand="PageNavigation" commandname="goto"/>
    <asp:linkbutton runat="server" id="navLink2" oncommand="PageNavigation" commandname="goto"/>
    <asp:linkbutton runat="server" id="navLink3" oncommand="PageNavigation" commandname="goto"/>
    <asp:linkbutton runat="server" id="navLink4" oncommand="PageNavigation" commandname="goto"/>
    <asp:linkbutton runat="server" id="navLink5" oncommand="PageNavigation" commandname="goto"/>

    <asp:imagebutton runat="server" id="next" imageurl="~/image/buttonnext.jpg" oncommand="PageNavigation" commandaname="Next"/>
    <asp:imagebutton runat="server"  id="last" imageurl="~/image/buttonlast.jpg" oncommand="PageNavigation" commandname="Last"/>
  </div>

And then in your prerender method do something like this

  if (datagrid.CurrentPageIndex > 2) Then
    navLink1.Text = (datagrid.currentPageIndex - 2).ToString()
    navLink1.CommandArgument = (datagrid.currentPageIndex - 2).ToString()
    navLink1.Visible = true
  else
    navLink1.Visible = false
  end if

  if (datagrid.CurrentPageIndex > 1) Then
    navLink2.Text = (datagrid.currentPageIndex - 1).ToString()
    navLink2.CommandArgument = (datagrid.currentPageIndex - 1).ToString()
    navLink2.Visible = true
  else
    navLink2.Visible = false
  end if

  navLink3.Text = (datagrid.currentPageIndex).ToString()
  navLink3.CommandArgument = (datagrid.currentPageIndex).ToString()

  ' now do the same for the page numbers on the other side of the current page index etc.


Obviously this solution doesn't scale that well if you want people to be able to click up to 100 page numbers.

HIH


 

by: CVSmarcPosted on 2006-04-16 at 22:06:36ID: 16467141

Thanks very much for your work.
The one thing i have found is this, http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcongeneratingclient-sidejavascriptforpostback.asp. It seems to be the proper way of implementing what i am thinking of doing with the JavaScript post back. I am just having a bit of trouble hooking it up with my code and detecting that the postback was an event that was triggered by the custom paging. If you can shed any light on this, that would be great.
Thanks ant  

 

by: asdaveyPosted on 2006-04-16 at 23:02:00ID: 16467246

OK so what you would now do is this:

In the PreRender method you would redner the following LiteralControl

Dim pages as new LiteralControl()

For i as Integer = -2 To 2
  Dim page as String = (datagrid.CurrentPageIndex + i).ToString()
  pages.Text += string.Format("<a href=""javascript:{0}"">{1}</a>&nbsp;", Page.GetPostBackEventReference(Me, page), page)
Next

pagesPlaceHolder.Controls.Add(pages)

Then you need to make sure you user control class implements the interface IPostBackEventHandler like so

      Public Sub RaisePostBackEvent(eventArgument As String) Implements IPostBackEventHandler.RaisePostBackEvent
         Dim index as Integer = Integer.Parse(eventArgument)
         DataGrid.CurrentPageIndex = index
      End Sub

HIH

Andy

 

by: CVSmarcPosted on 2006-04-19 at 21:16:30ID: 16494987

Just thought i would fill you in on how i got on. In short I have no luck in getting the above code up and running. I think this is mainly due to the way I have set up my customDataGrid class.

But basically to get this working, i created the HTML need to make up the pager as a string (thus cutting out all the complexity surrounded by dynamically creating all the controls i would need and binding events) and placed that string within a literal on the ASPX page. Then when ever the user selected one of the options within the custom build pager, a JavaScript function runs that received parameter (that indicated the page index that the user wishes to go to), placed that value within a hidden text box and posted the page back to the server. Now because this hidden is a webcontrol and has a server onchangeevent enabled on it, i am able to capitate any activity that the user makes with the paging as an event.

Now i don’t know how "elegant" you would consider this, but it works really well and i am able to create the most complex paging systems i want (as long as i can make the HTML for it) and the system will be able to use this custom "control" (although strictly specking I don’t think it is custom control in the strictest sense of the word) and run the required events.
Thanks again

ant

 

by: GranModPosted on 2006-05-19 at 00:32:13ID: 16715806

PAQed with points refunded (500)

GranMod
Community Support Moderator

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...