[英]Get parameter from URL on aspx page
How can I get parameter from URL on aspx page? 如何从aspx页面上的URL获取参数?
I have an application which has parameter ?id=12345abcd
and I want to get this id to select command in my gridview 我有一个参数为
?id=12345abcd
的应用程序,我想在GridView中获取此ID以选择命令
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. 并将此id从url插入查询中的变量
paramterFromUrl
中。
You can access that Id
by looking at the Request.QueryString
property in your code. 您可以通过查看代码中的
Request.QueryString
属性来访问该Id
。 For your use case, in the code behind, access that Id like: 对于您的用例,在后面的代码中,请按以下方式访问ID:
string Id= Request.QueryString["id"].ToString();
And use it in your SelectCommand
as: 并在
SelectCommand
中将其用作:
SelectCommand="SELECT [a], [b], [c], [d], [e], [f], [g], [h], [c] FROM [table] WHERE [c] =" + Id;
Please be aware of sql injection 请注意sql注入
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());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.