asp:repeater - headers at section change

后端 未结 5 936
无人共我
无人共我 2020-12-21 05:14

is there any way to bring up a subheader row at changes in a field in an databound asp:repeater control e.g.

Instead of

country | colour | number
uk | red         


        
5条回答
  •  -上瘾入骨i
    2020-12-21 06:11

    There seem to be a few bugs in the dotnetjunkies code but I've found a much simpler solution here http://www.west-wind.com/weblog/posts/140753.aspx

    Now repeaters don't support grouping, so you have to do this on your own, but it's pretty easy to do. In the repeater above the following data expression is responsible for the grouping:

    <%# this.RenderGroup(Eval("Group") as
    string) %> 
    

    The expression calls a method on the form to render an extra div tag. The code for this simple method looks like this:

    string LastGroup = "@#@~";
    protected string RenderGroup(string Group) {   
        if (Group == this.LastGroup)       
        return "";     // *** Group has changed    
        this.LastGroup = Group;    
        return "
    " +Group + "
    "; }

    This code gets called for every item and it simply checks to see if the group has changed. If it hasn't nothing is returned otherwise a simple div tag is returned as a string to embed into the markup. I chose to send back the HTML but I suppose you could also return true or false and conditionally render a control in the Repeater which would make the CSS Nazis happier .

提交回复
热议问题