Results 1 to 7 of 7

Thread: Pager template of DetailsView control not getting displayed

  1. #1

    Thread Starter
    Hyperactive Member Utpal's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    393

    Pager template of DetailsView control not getting displayed

    Hi everybody,

    I am trying to display a pager template for my details view control. In design view it is displayed. However, at run time it

    is not displayed. Following is the code I used for rendering the control:

    <aspetailsView
    ID="DetailsView1"
    runat="server"
    AllowPaging="True"
    DataSourceID="ObjectDataSource1" Height="129px" Width="488px">
    <PagerTemplate>
    <asp:Button
    id="btnFirst"
    Text="First"
    Runat="server" OnClick="btnFirst_Click" />
    <asp:Button
    id="btnLast"
    Text="Last"
    Runat="server" OnClick="btnLast_Click" />
    </PagerTemplate>
    </aspetailsView>

    Am I missing something?
    It is easy when you know it.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Pager template of DetailsView control not getting displayed

    Your code works for me. Are you sure the datasource is returning more than 1 row..

  3. #3

    Thread Starter
    Hyperactive Member Utpal's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    393

    Re: Pager template of DetailsView control not getting displayed

    I am deliberately returning 1 row; the first row if the "First" button is clicked and the last row if the "Last" button is clicked. Can't I keep them visible when only one row is returned?
    It is easy when you know it.

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Pager template of DetailsView control not getting displayed

    The default implementation of paging from an ObjectDataSource assumes the business object's select method returns all rows. The DetailsView "knows" which row to show and discards the rest. Since you are returning only 1 row it assumes there is only 1 total rows and so it does not show the paging template.

    In order to return only 1 row, you need to EnablePaging on the ObjectDataSource. This means the business object procedure that the ObjectDataSource calls (as defined by its SelectMethod) must have two arguments, Start Index and Maximum Rows. The business object should also implement a procedure to get a total record count. The procedure name is defined by the ObjectDataSource.SelectCountMethod.

    Also, by using the Button's CommandName and CommandArgument properties instead of the Click event, the DetailsView will automatically make the required procedure calls for any first, previous, next or last actions. Set the CommandName for all the buttons to "Page". The CommandArgument can be set to "First", "Next", "Prev" or "Last" where appropriate.

  5. #5

    Thread Starter
    Hyperactive Member Utpal's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    393

    Re: Pager template of DetailsView control not getting displayed

    I am aware of Data Source Paging, that you described, but the problem with that feature is that it requires you to have a stored procedure with the StartIndex and MaximumRows parameters, which I don't like, because every time a "previous" or "next" operation takes place, the current row's index number might change if another user inserts a new row having a lower primary key value than the current one or deletes a row having a lower primary key value than the current one, which might result in the requested action not taking place. So I was planning to fetch a single row at a time, using my own SQL commands, which would be placed in the Select procedure of the details view control and the requested navigate action and current primary key value would be passed as parameters, based on which a suitable SQL statement could be executed to retrieve the desired row.
    It is easy when you know it.

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Pager template of DetailsView control not getting displayed

    requires you to have a stored procedure with the StartIndex and MaximumRows parameters,
    Why? DetailsView calls the SelectMethod of the DataSourceObject with StartIndex and MaxRows. You then call any stored procedure with any parameters you want. Instead of using the "current row's index" to handle paging use the "current row's primary key value".

  7. #7

    Thread Starter
    Hyperactive Member Utpal's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    393

    Re: Pager template of DetailsView control not getting displayed

    I tried your idea, but the probem with that is, that only the next and last buttons are displayed when the form is displayed.

    Instead, I have placed the navigation buttons, outside the Details view and disabled paging in it and now it is working the way I wanted. The Details view serves the purpose of displaying the current row and providing the necessary environment for inserting, updating and deleting rows.
    It is easy when you know it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width