Reputation: 244
How can I get parameter from URL on aspx page?
I have an application which has parameter ?id=12345abcd
and I want to get this id to select command in my gridview
SelectCommand="SELECT [a], [b], [c], [d], [e], [f], [g], [h], [c] FROM [table] WHERE [c] = parameterFromUrl"
And insert this id from url inside variable paramterFromUrl
in query.
Upvotes: 2
Views: 12521
Reputation: 704
Try this:
sqlCommand.CommandText = "SELECT [a], [b], [c], [d], [e], [f], [g], [h], [c] FROM [table] WHERE [c] = @ParameterFromUrl";
sqlCommand.Parameters.AddWithValue("@ParameterFromUrl", Request.QueryString["id"].ToString());
Upvotes: 1
Reputation: 1824
You can access that Id
by looking at the Request.QueryString
property in your code. For your use case, in the code behind, access that Id like:
string Id= Request.QueryString["id"].ToString();
And use it in your SelectCommand
as:
SelectCommand="SELECT [a], [b], [c], [d], [e], [f], [g], [h], [c] FROM [table] WHERE [c] =" + Id;
Please be aware of sql injection
Upvotes: 5