如何根据嵌入式中继器中的字段对 DataGrid 列进行排序?
我有一个 DataGrid,其中有一列从 DataGrid 的 ItemDataBound 事件期间填充的中继器派生其内容。我需要能够根据中继器中的值对 DataGrid 行进行排序。下面是 DataGrid 的简化示例:
<DataGrid id="dgResults" Runat="server" AllowSorting="true">
<Columns>
<asp:boundcolumn HeaderText="ID" datafield="group_id" Visible="False" />
<asp:BoundColumn HeaderText="Group" DataField="group_name" SortExpression="group_name" />
<asp:TemplateColumn SortExpression="meeting_start_time">
<HeaderTemplate>
<asp:LinkButton CommandName="Sort" Text="Time" CausesValidation="False" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:Repeater ID="Schedule_Repeater" runat="server">
<ItemTemplate>
<%# Eval("meeting_start_time", "{0:t}")%>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</DataGrid>
如您所见,第三列包含会议开始时间,其值通过中继器显示。
如何告诉 DataGrid 按中继器中的 meeting_start_time
值对“时间”列进行排序?
I have a DataGrid which has one column that derives its contents from a Repeater that is populated during the DataGrid's ItemDataBound event. I need to be able to sort the DataGrid rows based on the value in the Repeater. Here is a shortened sample of the DataGrid:
<DataGrid id="dgResults" Runat="server" AllowSorting="true">
<Columns>
<asp:boundcolumn HeaderText="ID" datafield="group_id" Visible="False" />
<asp:BoundColumn HeaderText="Group" DataField="group_name" SortExpression="group_name" />
<asp:TemplateColumn SortExpression="meeting_start_time">
<HeaderTemplate>
<asp:LinkButton CommandName="Sort" Text="Time" CausesValidation="False" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:Repeater ID="Schedule_Repeater" runat="server">
<ItemTemplate>
<%# Eval("meeting_start_time", "{0:t}")%>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</DataGrid>
As you can see, the third column contains the meeting_start_time
, whose value is displayed via a Repeater.
How do I tell the DataGrid to sort the "Time" column by the meeting_start_time
values in the Repeater?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论