Stored Procedure to figure out the weeks and only display each week once:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[WordsByLetter]
AS
DECLARE @number int, @index int, @max int
CREATE TABLE #results ( number int, num INT)
SET @index=1
SET @max=52
WHILE @index <= @max
BEGIN
SET @number = @index
INSERT INTO #results Select number=@number, num=count(*) from WordWall
where Week=@number
SET @index = @index + 1
END
Select * FROM #results
RETURN
The full page code (including your last suggestion):
<script runat="server">
protected void hp1_Click(object sender, System.EventArgs e)
{
Filter = ((LinkButton)sender).Text;
SqlDataSource2.SelectParameters[0].DefaultValue = Filter;
}
string Filter
{
get
{
object o = ViewState["Filter"];
return (o != null) ? (string)o : string.Empty;
}
set
{
ViewState["Filter"] = value;
}
}
string linkClass(string number)
{
if (number == Filter)
{
return "selectedLetter";
}
else
{
return "";
}
}
protected void showall_Click(object sender, System.EventArgs e)
{
Filter = "";
SqlDataSource2.SelectParameters[0].DefaultValue = Filter;
}
public string PreFormat(string content)
{
if (content != null)
{
return content.Replace("\r\n", "<br/>");
}
else
{
return null;
}
}
private bool IsAdmin;
protected void Page_Load(object sender, System.EventArgs e)
{
IsAdmin = User.IsInRole("Administrators");
panel1.Visible = IsAdmin;
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
runat="Server">
<div id="body">
<Club:LoginBanner ID="LoginBanner1" runat="server" />
<!--
Left column
-->
<div id="columnleft">
<a name="content_start" id="content_start"></a>
<div class="leftblock">
<h2>
Word Wall</h2>
<p>
The purpose of this word wall is to keep you informed of
the spelling words that
your child is held accountable for. We call these the
"no excuses" words. They are
always up in the classroom, and now at home as well. I
hope that you will find this
helpful to you when working with your child. The word
wall will be updated on a
weekly bases as new words are added.</p>
</div>
</div>
<!--
Right column
-->
<div id="columnright">
<div class="rightblock">
<asp:Panel ID="panel1" runat="server"
CssClass="actionbuttons">
<Club:RolloverLink ID="RemoveBtn" runat="server"
Text="Add new Word" NavigateURL="WordWall_Edit.aspx?Action=New" />
</asp:Panel>
<div class="dashedline">
</div>
<div class="newscrumbs">
<asp:LinkButton ID="showall" runat="server" Text="Show
All" OnClick="showall_Click" />
<asp:SqlDataSource ConnectionString="<%$
ConnectionStrings:ClubSiteDB %>" ID="SqlDataSource1"
runat="server" SelectCommand="WordsByLetter"
SelectCommandType="StoredProcedure"/>
<asp:Repeater DataSourceID="SqlDataSource1"
ID="Repeater1" runat="server">
<ItemTemplate>
<asp:LinkButton ID="hp1" runat="server"
Text='<%#Convert.ToString(Eval("number"))%>' Visible='<%#
Convert.ToInt32(Eval("num")) > 0 %>'
OnClick="hp1_Click" CssClass='<%#
linkClass(Convert.ToString(Eval("number")))%>' />
</ItemTemplate>
</asp:Repeater>
</div>
<div class="dashedline">
</div>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"
ProviderName="<%$ ConnectionStrings:ClubSiteDB.ProviderName
%>"
SelectCommand="SELECT Week, ID, Words FROM WordWall WHERE
Week=@filter OR coalesce(@filter,0) = 0 ORDER BY Words ASC">
<SelectParameters>
<asp:Parameter DefaultValue="" Name="filter"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<asp:DataList ID="DataList1" runat="server"
DataSourceID="SqlDataSource2" HorizontalAlign="Center" RepeatColumns="1"
RepeatDirection="Vertical">
<ItemTemplate>
<asp:Panel ID="panel2" runat="server"
Visible='<%#IsAdmin %>'>
<Club:RolloverLink ID="EditBtn"
runat="server" Text="Edit" NavigateURL='<%#
"WordWall_Edit.aspx?Action=Edit&ArticleID=" + Convert.ToString( Eval("ID"))
%>' />
<Club:RolloverLink ID="RemoveBtn"
runat="server" Text="Remove" NavigateURL='<%#
"WordWall_Edit.aspx?Action=Remove&ArticleID=" + Convert.ToString( Eval("ID"))
%>' />
</asp:Panel>
<h1>
<asp:Label ID="WordsList" runat="server"
Font-Bold="true" Text= <%# (string) Eval("words") %>/>
</h1>
</div>
</ItemTemplate>
</asp:DataList>
</div>
</div>
<div class="clear2column">
</div>
</div>
</asp:Content>
--
Jeff Griffin
Windows XP Media Center Edition MVP
www.thegreenbutton.com www.jeffreygriffin.com [quoted text, click to view] "Omnibuzz" wrote:
> Can you paste the SP that you have.. I am not able to access the link that
> you gave...
>
> And also see...from this query
> SELECT ID, Words, Week
> FROM WordWall
> WHERE Week= @week OR coalesce(@week,'') = ''
>
> I am using
>
> coalesce(@week,'')
>
> and not
>
> coalesce(week,'')
>
> Why do I have the doubt that you are trying the latter :)
>
> And anyways.. try it this way if the week is numeric (of course I assume you
> don't have a week with value 0 in the table)
>