使用 GridView 进行子分组
我正在展示使用 Gridview 从数据库检索的数据。数据的形式如下: clientCode order#
因此任何给定的客户端都可以有多个订单。有没有一种简单的方法可以确保 ClientCode 不会在每个 GridView 行上重复?我知道我可以通过编程方式比较每一行,看看 clientCode 是否与前一行相比发生了变化,但这看起来相当野蛮。
编辑: 实际上,我更喜欢每个客户一行,然后是几行——客户行内的每个订单一行。不确定是否可以不嵌套 GridView。看起来有点矫枉过正。
在我的 aspx 文件中
<asp:GridView ID="gvProjectData" runat="server" AllowPaging="true"
AutoGenerateColumns="false"
DataKeyNames="p_clientcd,p_orderno"
PageSize="10"
EmptyDataText="No data"
CssClass="gridview" >
<Columns>
<asp:BoundField DataField="p_clientcd" HeaderText="Client" ReadOnly="true" ></asp:BoundField>
<asp:BoundField DataField="p_orderno" HeaderText="Order #" ReadOnly="true"></asp:BoundField>
</Columns>
</asp:GridView>
I am presenting data retrieved from the database using Gridview. The data is of the following form: clientCode order#
So any given client can have several orders. Is there a simple way to make sure that ClientCode is not repeated on every GridView row? I know I can programmatically compare each row to see if the clientCode has changed from the previous row, but this seems rather barbaric.
EDIT:
I would actually prefer ONE row per client, and then several rows - one per order inside the client row. Not sure if it's possible without nesting GridView. Seems like an overkill.
in my aspx file i have
<asp:GridView ID="gvProjectData" runat="server" AllowPaging="true"
AutoGenerateColumns="false"
DataKeyNames="p_clientcd,p_orderno"
PageSize="10"
EmptyDataText="No data"
CssClass="gridview" >
<Columns>
<asp:BoundField DataField="p_clientcd" HeaderText="Client" ReadOnly="true" ></asp:BoundField>
<asp:BoundField DataField="p_orderno" HeaderText="Order #" ReadOnly="true"></asp:BoundField>
</Columns>
</asp:GridView>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Matt Berseth 使用 ListView 做了与此非常相似的事情。
Matt Berseth did something very similar to this using ListView.