1

我必须过滤人们的注册日期,但我不知道该怎么做。

我的网格视图:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:UtentiRegistratiConnectionString1 %>" DeleteCommand="DELETE FROM [Utenti] WHERE [Id] = @Id" InsertCommand="INSERT INTO [Utenti] ([Nome], [Cognome], [Cellulare], [CodiceFiscale], [IndirizzoEmail], [Password], [Prenotazioni], [Acquisti], [Bonus], [DataRegistrazione]) VALUES (@Nome, @Cognome, @Cellulare, @CodiceFiscale, @IndirizzoEmail, @Password, @Prenotazioni, @Acquisti, @Bonus, @DataRegistrazione)" SelectCommand="SELECT [Id], [Nome], [Cognome], [Cellulare], [CodiceFiscale], [IndirizzoEmail], [Password], [Prenotazioni], [Acquisti], [Bonus], [DataRegistrazione] FROM [Utenti]" UpdateCommand="UPDATE [Utenti] SET [Nome] = @Nome, [Cognome] = @Cognome, [Cellulare] = @Cellulare, [CodiceFiscale] = @CodiceFiscale, [IndirizzoEmail] = @IndirizzoEmail, [Password] = @Password, [Prenotazioni] = @Prenotazioni, [Acquisti] = @Acquisti, [Bonus] = @Bonus, [DataRegistrazione] = @DataRegistrazione WHERE [Id] = @Id">
    <DeleteParameters>
        <asp:Parameter Name="Id" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="Nome" Type="String" />
        <asp:Parameter Name="Cognome" Type="String" />
        <asp:Parameter Name="Cellulare" Type="String" />
        <asp:Parameter Name="CodiceFiscale" Type="String" />
        <asp:Parameter Name="IndirizzoEmail" Type="String" />
        <asp:Parameter Name="Password" Type="String" />
        <asp:Parameter Name="Prenotazioni" Type="Int32" />
        <asp:Parameter Name="Acquisti" Type="Int32" />
        <asp:Parameter Name="Bonus" Type="String" />
        <asp:Parameter DbType="DateTime2" Name="DataRegistrazione" />
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="Nome" Type="String" />
        <asp:Parameter Name="Cognome" Type="String" />
        <asp:Parameter Name="Cellulare" Type="String" />
        <asp:Parameter Name="CodiceFiscale" Type="String" />
        <asp:Parameter Name="IndirizzoEmail" Type="String" />
        <asp:Parameter Name="Password" Type="String" />
        <asp:Parameter Name="Prenotazioni" Type="Int32" />
        <asp:Parameter Name="Acquisti" Type="Int32" />
        <asp:Parameter Name="Bonus" Type="String" />
        <asp:Parameter DbType="DateTime2" Name="DataRegistrazione" />
        <asp:Parameter Name="Id" Type="Int32" />
    </UpdateParameters>
</asp:SqlDataSource>

Data di Registrazione: Da&nbsp;
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
&nbsp;a
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
&nbsp;&nbsp;
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Filtra" CssClass="filtra" />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" EmptyDataText="Nessun record di dati da visualizzare." Font-Size="Small" PageSize="15">
    <Columns>
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
        <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
        <asp:BoundField DataField="Nome" HeaderText="Nome" SortExpression="Nome" />
        <asp:BoundField DataField="Cognome" HeaderText="Cognome" SortExpression="Cognome" />
        <asp:BoundField DataField="Cellulare" HeaderText="Cellulare" SortExpression="Cellulare" />
        <asp:BoundField DataField="CodiceFiscale" HeaderText="CodiceFiscale" SortExpression="CodiceFiscale" />
        <asp:BoundField DataField="IndirizzoEmail" HeaderText="IndirizzoEmail" SortExpression="IndirizzoEmail" />
        <asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" />
        <asp:BoundField DataField="Prenotazioni" HeaderText="Prenotazioni" SortExpression="Prenotazioni" />
        <asp:BoundField DataField="Acquisti" HeaderText="Acquisti" SortExpression="Acquisti" />
        <asp:BoundField DataField="Bonus" HeaderText="Bonus" SortExpression="Bonus" />
        <asp:BoundField DataField="DataRegistrazione" HeaderText="DataRegistrazione" SortExpression="DataRegistrazione" />
    </Columns>
</asp:GridView>

在 CodeBehind 我尝试过:

protected void Button2_Click(object sender, EventArgs e)
{
    DateTime datada = DateTime.Parse(TextBox3.Text);
    DateTime dataa = DateTime.Parse(TextBox4.Text).AddDays(1);
    SqlDataSource Prova = new SqlDataSource();
    Prova.SelectCommand = "Select * from Utenti where DataRegistrazione>=@vdadatareg and DataRegistrazione<=@vadatareg";
    Prova.ID = "proviamoci";
    GridView1.DataSourceID = Prova.ID;

}

或者:

protected void Button2_Click(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection(strcon);
    SqlCommand cmd = new SqlCommand("Select * from Utenti order by Id Asc", con);
    SqlDataAdapter adp = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    con.Open();
    adp.Fill(ds, "Utenti");
    cmd.ExecuteNonQuery();
    con.Close();
    GridView1.DataSource = ds;
    GridView1.DataBind();
}

但是它们不起作用...我该怎么办?我需要过滤gridview。我必须输入一个“注册日期”-> 从“日期”到“日期”。

4

1 回答 1

0

不关心控件类型:(示例)

<asp:sqldatasource
          id="SqlDataSource1"
          runat="server"
          connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
          selectcommand="SELECT LastName FROM Employees WHERE Title = @Title">
          <selectparameters>
              <asp:controlparameter name="Title" controlid="yourTextBox" propertyname="Text"/>
          </selectparameters>
      </asp:sqldatasource>
于 2013-07-29T12:46:40.040 回答