VB.NET 中继器按月分组
我的中继器正在搜索 SQL Server 数据库中的日期并返回每个月的前 3 个字母。有没有办法按照我想要的方式显示中继器?
<asp:repeater id="rptLetters" runat="server" datasourceid="dsLetters">
<headertemplate>
|
</headertemplate>
<itemtemplate>
<asp:linkbutton id="btnLetter" runat="server" onclick="btnLetter_Click" text='<%#Eval("Letter")%>' />
</itemtemplate>
<separatortemplate>
|
</separatortemplate>
</asp:repeater>
<asp:DropDownList ID="ddlLetters" runat="server" Visible="False" DataSourceID="dsLetters">
</asp:DropDownList>
<asp:sqldatasource id="dsLetters" runat="server" connectionstring="<%$
ConnectionStrings:ProductsConnectionString %>"
selectcommand="SELECT DISTINCT LEFT
(p.LaunchDate, 3) AS [Letter]
FROM Product p, Category c
WHERE c.ParentID = 37
AND p.LaunchDate IS NOT NULL">
</asp:sqldatasource>
显示为:全部|四月 |八月 |十二月 |二月 |简 |七月 |君|三月 |五月 |十一月 |十月 |九月
想要:全部 |简 |二月 |三月 |四月 |五月 |君|七月 |八月 |九月 |十月 |十一月 |十二月
My repeater is searching through dates in the SQL Server database and returning the first 3 letters of every month. Is there a way to show the repeater the way I want to?
<asp:repeater id="rptLetters" runat="server" datasourceid="dsLetters">
<headertemplate>
|
</headertemplate>
<itemtemplate>
<asp:linkbutton id="btnLetter" runat="server" onclick="btnLetter_Click" text='<%#Eval("Letter")%>' />
</itemtemplate>
<separatortemplate>
|
</separatortemplate>
</asp:repeater>
<asp:DropDownList ID="ddlLetters" runat="server" Visible="False" DataSourceID="dsLetters">
</asp:DropDownList>
<asp:sqldatasource id="dsLetters" runat="server" connectionstring="<%$
ConnectionStrings:ProductsConnectionString %>"
selectcommand="SELECT DISTINCT LEFT
(p.LaunchDate, 3) AS [Letter]
FROM Product p, Category c
WHERE c.ParentID = 37
AND p.LaunchDate IS NOT NULL">
</asp:sqldatasource>
Shows up as: ALL | Apr | Aug | Dec | Feb | Jan | Jul | Jun | Mar | May | Nov | Oct | Sep
Would like: ALL | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尽管上面建议不要这样做,但这演示了如何在提取不同的依赖项之前处理对依赖项进行排序的需要:
对于这种特殊情况,您不应该使用查询来提取月份缩写,假设默认的日期到字符串转换将允许您左边的 3 个字符是准确的月份缩写。
Despite advising against it above, this demonstrates how to handle the need to order on a dependency before extracting distinct:
For this particular case, you should not use a query to extract the month abbreviations assuming that the default date-to-string conversion will let your left 3 characters be an accurate month abbreviation.
我放弃了中继器的想法,只是使用链接按钮来列出月份。然后,我的 SQL 查询将根据单击的月份查找结果。
I ditched the repeater idea, and am just using linkbuttons to list the months. My SQL query will then find results based on which month is clicked.