有没有办法在数据绑定 asp:repeater 控件中的字段更改时显示子标题行,例如
代替
<上一页>国家 |颜色 |数字英国 |红色 |3英国 |绿色 |3法国| 家企业红3这样做:
<上一页>==英国==颜色 |数字红色 |3绿色 3==法国==颜色 |数字红色 |3非常感谢您的帮助.
dotnetjunkies 代码中似乎有一些错误,但我在这里找到了一个更简单的解决方案 http://www.west-wind.com/weblog/posts/140753.aspx
现在中继器不支持分组,所以你必须自己做这件事,但这很容易做到.在上面的转发器中,以下数据表达式负责分组:
<%# this.RenderGroup(Eval("Group") as字符串) %>
表达式调用表单上的一个方法来呈现一个额外的 div 标签.这个简单方法的代码如下所示:
string LastGroup = "@#@~";受保护的字符串渲染组(字符串组){如果(组 == this.LastGroup)返回 "";//*** 组已更改this.LastGroup = 组;return "<div class='groupheader'>"+组+</div>";}
每个项目都会调用此代码,它只是检查组是否已更改.如果没有返回任何内容,否则返回一个简单的 div 标签作为字符串嵌入到标记中.我选择发回 HTML,但我想你也可以返回 true 或 false 并有条件地在 Repeater 中渲染一个控件,这将使 CSS Nazis 更快乐.
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 | 3 uk | green | 3 france | red 3
Do this:
==UK== colour | number red | 3 green 3 ==FRANCE== colour | number red | 3
Many thanks for any help.
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 "<div class='groupheader'>" +Group + "</div>";
}
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 .
这篇关于asp:repeater - 部分更改的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!