I am using querystring for passing a value which is used to select the subscription category (variable name subno) on second page.
Based on the subscription category (subno is specified as integer in sql server as part of table categories) second page is invoked using the following URL-
http://localhost:53175/v1/ProductsList.aspx?subno=1
or
http://localhost:53175/v1/ProductsList.aspx?subno=2
In the second page subno is used to query the items based on subno passed.
<asp:SqlDataSource ID="subscription" runat="server"
ConnectionString="<%$ ConnectionStrings:aimnbde3ConnectionString %>"
SelectCommand="SELECT [subscription] FROM [subscription] WHERE ([subno] = @subno)">
<SelectParameters>
<asp:QueryStringParameter Name="subno" QueryStringField="subno" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
This code works well if category(varibale subno) is passed.
In case second page is called directly like
http://localhost:53175/v1/ProductsList.aspx
Then value of subno is interpreted as 0. Do we have a way to change the query(SelectCommand=”SELECT [subscription] FROM [subscription] ) based on value of subno ?
Or please suggest the right way to handle the case where subno is not passed
Editing –
Sorry for missing an important part of question-
When http://localhost:53175/v1/ProductsList.aspx is accessing i want to display all the products so the query will be
SELECT [subscription] FROM [subscription]
and in case a value is passed query will be
SELECT [subscription] FROM [subscription] WHERE ([subno] = @subno)
I would change the query to this:
and then add the following to the parameter
and the following to the SQLDataSource
So your code would look like this: