Passing a Parameter on a query string
In ASP.NET, you can pass a parameter to a SqlDataSource control on a query string. Here are the steps:
Define a parameter in your markup, for example:
<asp:SqlDataSource ID=”SqlDataSource1″ runat=”server” ConnectionString=”<%$ ConnectionStrings:NorthwindConnectionString %>”
SelectCommand=”SELECT * FROM Orders WHERE CustomerID = @CustomerID”>
<SelectParameters>
<asp:QueryStringParameter Name=”CustomerID” QueryStringField=”CustomerId” Type=”String” />
</SelectParameters>
</asp:SqlDataSource>
Set the QueryStringField property of the QueryStringParameter object to the name of the query string variable that contains the value you want to use as the parameter:
<asp:QueryStringParameter Name=”CustomerID” QueryStringField=”CustomerId” Type=”String” />
In this example, the Name property of the parameter is set to “CustomerID”, which is the name of the parameter in the SQL query. The QueryStringField property of the QueryStringParameter object is set to “CustomerId”, which is the name of the query string variable that contains the value you want to use as the parameter.
Add the parameter to the URL of the page that contains the SqlDataSource control:
http://localhost/mypage.aspx?CustomerId=ALFKI
Run your application to see the results. Now, when the SqlDataSource control is executed, it will use the value of the query string variable as the value of the “CustomerID” parameter in the query. You can change the value of the query string variable in the URL, and the SqlDataSource control will use the new value as the value of the parameter.
Apply for ASP.NET Certification Now!!
https://www.vskills.in/certification/certified-aspnet-programmer