Customize ASP.Net DataPager generated HTML

前端 未结 2 375
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-05 16:29

I am using a ListView and DataPager in my web project for pagination. It works fine, but the generated HTML for the pagination is simply a span containing some hyperlinks.

2条回答
  •  甜味超标
    2021-01-05 17:26

    You can use the PagerTemplate to designate the markup you'd like to use for the paging control. I'm not sure exactly what you're trying to do in terms of displaying the paging information as as ul/li, but this should be enough to start you on the right track. Sorry for the code running long to the side...

    ex:

    
                
                    
                        
                            Page
                            
                            of
                            
                        
                    
    

    EDIT: here is a more detailed beginning to a solution for this:

    
         
              
               
         
    
    

    And here is what you would have in the code-behind:

    protected void listPages_Click(object sender, BulletedListEventArgs e)
            {
                var pageNo = int.Parse((sender as BulletedList).Items[e.Index].Text);
                var startIndex = (pageNo - 1) * DataPager1.PageSize;
                DataPager1.SetPageProperties(startIndex, DataPager1.PageSize, true);
            }
    

    What remains for you to do is to perform a databinding on the bulleted list against a method that gets the page count and returns an IEnumerable list of the text you want for the page links. Standard warning: this is sample code, and probably shouldn't be used in a production environment without a thorough vetting! :)

提交回复
热议问题