VB.NET 中继器按月分组

发布于 2024-12-27 23:43:44 字数 1038 浏览 1 评论 0原文

我的中继器正在搜索 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

始终不够 2025-01-03 23:43:44

尽管上面建议不要这样做,但这演示了如何在提取不同的依赖项之前处理对依赖项进行排序的需要:

select distinct left(launchdate,3) as Abbreviated from
(   select * from product 
    where launchdate is not null order by month(launchdate) asc) p,     
category c where c.parentid=@ParentId 

对于这种特殊情况,您不应该使用查询来提取月份缩写,假设默认的日期到字符串转换将允许您左边的 3 个字符是准确的月份缩写。

Despite advising against it above, this demonstrates how to handle the need to order on a dependency before extracting distinct:

select distinct left(launchdate,3) as Abbreviated from
(   select * from product 
    where launchdate is not null order by month(launchdate) asc) p,     
category c where c.parentid=@ParentId 

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.

宁愿没拥抱 2025-01-03 23:43:44

我放弃了中继器的想法,只是使用链接按钮来列出月份。然后,我的 SQL 查询将根据单击的月份查找结果。

<asp:linkbutton id="btnAll" runat="server" text="ALL" onclick="btnAll_Click" /> |
<asp:linkbutton id="btnJan" runat="server" text="Jan" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnFeb" runat="server" text="Feb" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnMar" runat="server" text="Mar" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnApr" runat="server" text="Apr" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnMay" runat="server" text="May" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnJune" runat="server" text="June" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnJuly" runat="server" text="July" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnAug" runat="server" text="Aug" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnSep" runat="server" text="Sep" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnOct" runat="server" text="Oct" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnNov" runat="server" text="Nov" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnDec" runat="server" text="Dec" onclick="btnMonths_Click" />



SELECT p.ProductID, p.ProductName, p.LaunchDate 
FROM Product p JOIN CategoryLink l 
ON p.ProductID = l.ProductID 
JOIN Category c ON c.CategoryID = l.CategoryID 
WHERE(p.LaunchDate LIKE '{0}%') 
AND c.ParentID = '37' 
AND p.ProductName IS NOT NULL 
ORDER BY Month(p.LaunchDate), Day(p.LaunchDate)

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.

<asp:linkbutton id="btnAll" runat="server" text="ALL" onclick="btnAll_Click" /> |
<asp:linkbutton id="btnJan" runat="server" text="Jan" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnFeb" runat="server" text="Feb" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnMar" runat="server" text="Mar" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnApr" runat="server" text="Apr" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnMay" runat="server" text="May" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnJune" runat="server" text="June" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnJuly" runat="server" text="July" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnAug" runat="server" text="Aug" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnSep" runat="server" text="Sep" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnOct" runat="server" text="Oct" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnNov" runat="server" text="Nov" onclick="btnMonths_Click" /> |
<asp:linkbutton id="btnDec" runat="server" text="Dec" onclick="btnMonths_Click" />



SELECT p.ProductID, p.ProductName, p.LaunchDate 
FROM Product p JOIN CategoryLink l 
ON p.ProductID = l.ProductID 
JOIN Category c ON c.CategoryID = l.CategoryID 
WHERE(p.LaunchDate LIKE '{0}%') 
AND c.ParentID = '37' 
AND p.ProductName IS NOT NULL 
ORDER BY Month(p.LaunchDate), Day(p.LaunchDate)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文