ListView with DataPager not working

后端 未结 7 919
[愿得一人]
[愿得一人] 2021-02-07 05:00

From everything I\'ve read, it seemed that adding paging to a ListView control should be dead simple, but it\'s not working for me. After adding the ListView and DataPager contr

7条回答
  •  星月不相逢
    2021-02-07 05:45

    Also, if the data source of your ListView is changed (e.g. if displaying data based on search parameters), don't forget to reset the pager every time the data source is updated. With a ListView this is not as straightforward as some other data-bound controls (e.g. GridView):

    private void ResetListViewPager()
    {
        DataPager pager = (DataPager)ListViewMembers.FindControl("DataPager1");
        if (pager != null)
        {
            CommandEventArgs commandEventArgs = new CommandEventArgs(DataControlCommands.FirstPageCommandArgument, "");
            // MAKE SURE THE INDEX IN THE NEXT LINE CORRESPONDS TO THE CORRECT FIELD IN YOUR PAGER
            NextPreviousPagerField nextPreviousPagerField = pager.Fields[0] as NextPreviousPagerField;
            if (nextPreviousPagerField != null)
            {
                nextPreviousPagerField.HandleEvent(commandEventArgs);
            }
    
            // THIS COMMENTED-OUT SECTION IS HOW IT WOULD BE DONE IF USING A NUMERIC PAGER RATHER THAN A NEXT/PREVIOUS PAGER
            //commandEventArgs = new CommandEventArgs("0", "");
            //NumericPagerField numericPagerField = pager.Fields[0] as NumericPagerField;
            //if (numericPagerField != null)
            //{
            //    numericPagerField.HandleEvent(commandEventArgs);
            //}
        }
    }
    

提交回复
热议问题