在calendar控件中选择了日期后,希望能够在sqldatasourse控件中用where语句读到选择日期的年和月,然后筛选出符合该年月的项,在gridview控件中列出来,但是却不成功,请各位帮帮忙。代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC" 
            BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest" 
            FirstDayOfWeek="Monday" Font-Names="Verdana" Font-Size="8pt" 
            ForeColor="#663399" Height="200px" 
            onselectionchanged="Calendar1_SelectionChanged" SelectionMode="DayWeekMonth" 
            ShowGridLines="True" Width="220px" SelectedDate="2012-03-22">
            <DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
            <NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
            <OtherMonthDayStyle ForeColor="#CC9966" />
            <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
            <SelectorStyle BackColor="#FFCC66" />
            <TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" 
                ForeColor="#FFFFCC" />
            <TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
        </asp:Calendar>
        <br />        <br />
        <br />
        <%
            Label1.Text = Calendar1.SelectedDate.ToShortDateString();
    
        %>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
       <%
           DateTime d = Calendar1.SelectedDate;
           int y,x;
           string s;
           y = d.Year;
           x = d.Month;
           s = y + "-" + x;
       %>
       <br /> <%=s %>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:attendanceConnectionString %>" 
            
            
            SelectCommand="SELECT [id] FROM [paiban] WHERE ([att_data] = @att_data)" 
            onselecting="SqlDataSource1_Selecting">
            <SelectParameters>
                <asp:CookieParameter CookieName="s" Name="att_data" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="id" HeaderText="id" SortExpression="id" />
            </Columns>
        </asp:GridView>        <br />
    </div>
    
    </form>
</body>
</html>