asp:repeater - 部分更改的标题

0

本文介绍了asp:repeater - 部分更改的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

有没有办法在数据绑定 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 - 部分更改的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Func&lt;string,string&gt; 有什么区别?和委托?
What is the difference between Funclt;string,stringgt; and delegate?(Funclt;string,stringgt; 有什么区别?和委托?)...
2023-11-11 C#/.NET开发问题
3

从串口解析/格式化数据 - C#
Parsing/formatting data from serial port - C#(从串口解析/格式化数据 - C#)...
2023-11-10 C#/.NET开发问题
6

ASP.NET MVC 中的 &lt;%: 和 &lt;%= 有什么区别?
What is the difference between lt;%: and lt;%= in ASP.NET MVC?(ASP.NET MVC 中的 lt;%: 和 lt;%= 有什么区别?)...
2023-11-10 C#/.NET开发问题
0

标签系统的 linq 查询 - 搜索多个标签
linq query for tag system - search for multiple tags(标签系统的 linq 查询 - 搜索多个标签)...
2023-11-10 C#/.NET开发问题
0

论坛标签.实施它们的最佳方法是什么?
Forum tags. What is the best way to implement them?(论坛标签.实施它们的最佳方法是什么?)...
2023-11-10 C#/.NET开发问题
1

html 脚本标签未使用类型 javascript &lt;script type=&quot;text
html script tag not using type javascript lt;script type=quot;text/htmlquot;gt;?(html 脚本标签未使用类型 javascript lt;script type=quot;text/htmlgt;gt;?)...
2023-11-10 C#/.NET开发问题
6