在同一页面上的查询中生成输出 [英] Generating output on query on the same page

查看:66
本文介绍了在同一页面上的查询中生成输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个ASP.NET网站,我必须在其中执行某些操作.我必须以{1:2:3:4}格式显示数据库在 menu.aspx页上的ID.上面的格式没有问题,可以用
编写

Hi,

I have an ASP.NET website in which I have to perform a certain operation. I have to displaying the ID''s from the DB on menu.aspx page in this format {1:2:3:4}. The above format is not a problem and can be just be written with

Response.Write("{");
for.. loop(until last ID)
{
Response.Write(query to fetch ID''s) + ":";
}
Response.Write("}");



但是,这是我的问题.当用户在URL中键入查询时,我必须生成此ID,有点像http://localhost/website/menu.aspx?search=yes

请注意,我是说 用户将键入此URL .我知道查询字符串可以将值从一种形式传递到另一种形式,但这是单个Web形式,如果我附加此?search=yes,它应该返回结果.该怎么办呢?
与在Google中搜索类似.例如:我可以输入www.google.com/search?CP并得到结果

编辑
-
我正在使用这个小的代码段作为查询字符串



But here comes my question. I have to generate this ID when the user types the query within the URL somewhat like http://localhost/website/menu.aspx?search=yes

Note that I am saying that the user will type this URL. I know that query string can pass the values from one form to another but this is a single web form and if I attach this ?search=yes, it should return the result. How can this be done?
Something similar to searching in Google. For eg: I can type www.google.com/search?CP and I get the results

Edit
--
I am using this small code snippet for the query string

if (Request.QueryString["search"] != null) {

    Response.Write("{");
    for.. loop(until last ID) {
        Response.Write(query to fetch ID''s) + ":";
    }
    Response.Write("}");
}



我必须更改一些内容,以便在此查询字符串localhost/website/?search=codeproject上,将代码项目附加到我的输出即codeproject{1:2:3:4)上.同样,对于通过查询字符串搜索的所有其他值,应将其附加到输出中.



I have to change some things so that on this query string localhost/website/?search=codeproject , the codeproject should be appended to my output i.e codeproject{1:2:3:4). Similarly for all other values searched through query string should be appended to the output. How to do this?

推荐答案

您可以使用
获取查询字符串的值
You can get the value of your query string using

Request.QueryString["search"]



您可以将查询字符串值分配给字符串变量,然后使用Response.Write
附加ID并放出字符串变量
如果(Request.QueryString ["search"]!= null)
{
字符串outputText = Request.QueryString ["search"].ToString()+"{";
for .. loop(直到最后一个ID){
outputText + =(获取ID的查询)+:";
}
outputText + =}";
Response.Write(outputText);
}

注意:您可以使用String类的可用方法来附加字符串,以获得更好的性能

希望对您有帮助
Hi
You can assign the query string value to a string variable and append the id''s and out put the string variable using Response.Write

if (Request.QueryString["search"] != null)
{
string outputText = Request.QueryString["search"].ToString() + "{";
for.. loop(until last ID) {
outputText += (query to fetch ID''s) + ":";
}
outputText += "}";
Response.Write(outputText);
}

NB: You can use String class available method for appending the strings for better performance

Hope this helps


这篇关于在同一页面上的查询中生成输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆