Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET C# CodeBehind DB Filter a GridView with a textbox
    primarykey
    data
    text
    <p>I have to filter the Registration Date of people, but I don't know how I can do.</p> <p>My grid view:</p> <pre><code>&lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:UtentiRegistratiConnectionString1 %&gt;" 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"&gt; &lt;DeleteParameters&gt; &lt;asp:Parameter Name="Id" Type="Int32" /&gt; &lt;/DeleteParameters&gt; &lt;InsertParameters&gt; &lt;asp:Parameter Name="Nome" Type="String" /&gt; &lt;asp:Parameter Name="Cognome" Type="String" /&gt; &lt;asp:Parameter Name="Cellulare" Type="String" /&gt; &lt;asp:Parameter Name="CodiceFiscale" Type="String" /&gt; &lt;asp:Parameter Name="IndirizzoEmail" Type="String" /&gt; &lt;asp:Parameter Name="Password" Type="String" /&gt; &lt;asp:Parameter Name="Prenotazioni" Type="Int32" /&gt; &lt;asp:Parameter Name="Acquisti" Type="Int32" /&gt; &lt;asp:Parameter Name="Bonus" Type="String" /&gt; &lt;asp:Parameter DbType="DateTime2" Name="DataRegistrazione" /&gt; &lt;/InsertParameters&gt; &lt;UpdateParameters&gt; &lt;asp:Parameter Name="Nome" Type="String" /&gt; &lt;asp:Parameter Name="Cognome" Type="String" /&gt; &lt;asp:Parameter Name="Cellulare" Type="String" /&gt; &lt;asp:Parameter Name="CodiceFiscale" Type="String" /&gt; &lt;asp:Parameter Name="IndirizzoEmail" Type="String" /&gt; &lt;asp:Parameter Name="Password" Type="String" /&gt; &lt;asp:Parameter Name="Prenotazioni" Type="Int32" /&gt; &lt;asp:Parameter Name="Acquisti" Type="Int32" /&gt; &lt;asp:Parameter Name="Bonus" Type="String" /&gt; &lt;asp:Parameter DbType="DateTime2" Name="DataRegistrazione" /&gt; &lt;asp:Parameter Name="Id" Type="Int32" /&gt; &lt;/UpdateParameters&gt; &lt;/asp:SqlDataSource&gt; Data di Registrazione: Da&amp;nbsp; &lt;asp:TextBox ID="TextBox3" runat="server"&gt;&lt;/asp:TextBox&gt; &amp;nbsp;a &lt;asp:TextBox ID="TextBox4" runat="server"&gt;&lt;/asp:TextBox&gt; &amp;nbsp;&amp;nbsp; &lt;asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Filtra" CssClass="filtra" /&gt; &lt;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"&gt; &lt;Columns&gt; &lt;asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /&gt; &lt;asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" /&gt; &lt;asp:BoundField DataField="Nome" HeaderText="Nome" SortExpression="Nome" /&gt; &lt;asp:BoundField DataField="Cognome" HeaderText="Cognome" SortExpression="Cognome" /&gt; &lt;asp:BoundField DataField="Cellulare" HeaderText="Cellulare" SortExpression="Cellulare" /&gt; &lt;asp:BoundField DataField="CodiceFiscale" HeaderText="CodiceFiscale" SortExpression="CodiceFiscale" /&gt; &lt;asp:BoundField DataField="IndirizzoEmail" HeaderText="IndirizzoEmail" SortExpression="IndirizzoEmail" /&gt; &lt;asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" /&gt; &lt;asp:BoundField DataField="Prenotazioni" HeaderText="Prenotazioni" SortExpression="Prenotazioni" /&gt; &lt;asp:BoundField DataField="Acquisti" HeaderText="Acquisti" SortExpression="Acquisti" /&gt; &lt;asp:BoundField DataField="Bonus" HeaderText="Bonus" SortExpression="Bonus" /&gt; &lt;asp:BoundField DataField="DataRegistrazione" HeaderText="DataRegistrazione" SortExpression="DataRegistrazione" /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>In the CodeBehind I have tried:</p> <pre><code>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&gt;=@vdadatareg and DataRegistrazione&lt;=@vadatareg"; Prova.ID = "proviamoci"; GridView1.DataSourceID = Prova.ID; } </code></pre> <p>Or:</p> <pre><code>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(); } </code></pre> <p>But they doesn't work... How I can do? I need to filter the gridview. I have to put a "Registration date" -> from "date" to "date".</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload