我的转发器正在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>
显示为:ALL |四月|八月| 12月|二月| Jan |七月|君| Mar |五月| 11月|十月|月
想:ALL | Jan |二月| Mar |四月|五月|君|七月|八月|九月|十月| 11月|癸
答案 0 :(得分:0)
尽管上面提出了反对意见,但这演示了如何在提取不同内容之前处理对依赖项进行排序的需求:
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个字符成为准确的月份缩写。
答案 1 :(得分:0)
我放弃了转发器的想法,我只是使用链接按钮来列出月份。然后,我的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)