Hi Folks.
I am hoping to gain some insight into why what I am trying does now work. Chances are it is a newbie coding error but there may be another reason.
I am creating an aspx page with a sqldatasource and a gridview. When a checkbox is checked, I want the SelectCommand property to change to a different SQl Query so that the gridview shows different information.
The current code does not throw an error but also shows no data. I am looking for ideas why.
VB CODE
Public Property Query() As String
Get
Return _query
End Get
Set(ByVal value As String)
_query = value
End Set
End Property
Protected Sub chk1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chk1.CheckedChanged
If chk1.Checked = False Then
Query() = "SELECT * FROM [Purchases] WHERE ([Dateordered] LIKE '%' + @Dateordered + '%') ORDER BY [Dateordered] DESC"
Else
Query() = "SELECT * FROM [Purchases] WHERE (([Dateordered] LIKE '%' + @Dateordered + '%') AND ([Datereceived] = '')) ORDER BY [Id] DESC"
End If
End Sub
SQL DataSource on ASPX Page
<asp:SqlDataSource ID="dsSQL1" runat="server" ConnectionString="<%$ ConnectionStringsSKBConnectionString1 %>" SelectCommand='<%# Query() %>'>
<SelectParameters>
<asp:ControlParameter ControlID="ddlmonths" DefaultValue="Jan" Name="Dateordered"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
SKBConnectionString1 %>" SelectCommand='<%# Query() %>'>