在解决与查询字符串和响应有关的问题时令人困惑.redirct.(更新) [英] confusing in solving the problem related to query string and response.redirct.(Updated)
问题描述
已改进的问题.已更新.
首先,我有一个问题,要从主页获取ProductIds到Product Catalog.aspx页面..
现在,当我在编码中进行一些更改时,如下所示.我将ProductsIDs表单的主页获取到ProductCatalog.aspx页面.我使用调试器进行了检查.在主页上,我进行了一些轻松的更改.现在ID将转到productcatalog.aspx页面.
Improved Question.. Updated.
First i have a problem of getting the ProductIds from main page to Product Catalog.aspx Page..
Now when i make some Changes in the coding as below. i am getting the ProductsIDs form main page to ProductCatalog.aspx page.I Used debugger to check that. On main page i made the fallowing changes. now ids are going to productcatalog.aspx page.
string querydr = "select * from Products";
SqlDataReader dr = obj.fillcomb(querydr);
while (dr.Read())
{
if(proid == String.Empty)
{
proid = dr["ProductID"].ToString();
}
else
{
proid += "," + dr["ProductID"].ToString();
}
}
Response.Redirect("ProductCatalog.aspx?ID="+proid);
我使用调试器检查了ProductCatalog.aspx页面上的情况..
我在产品catalog.aspx页上的查询中看到了令人讨厌的东西.
我将查询放在productcatalog.aspx页中为
I used Debugger to check that whats going on on ProductCatalog.aspx Page..
I saw that i am getting the fallowing thing in my query on product catalog.aspx page..
I put the query in productcatalog.aspx page as
string query = "Select * from Products where ProductID= '" + Request.QueryString["ID"].ToString() +"' AND UnitCost < 5000";
在dubbugger上,我看到查询按如下方式运行.
and on dubbugger i saw that the query runs as below.
query "Select * from Products where ProductID= ',63,64,65' AND UnitCost < 5000" string
ID为63和64的产品的价格(单位成本)<5000,但在gridview中什么也没有显示.任何人都可以帮助解决问题所在的地方
在ProductCatalog.aspx页面上,我具有以下代码
the products with ids have 63 and 64 have price(UnitCost) <5000 but nothing is shown in gridview. can anyone help on that where is the problem
on ProductCatalog.aspx page i have the code as below
private void LoadGridView()
{
// string query = "Select * from Products where CategoryID='" + Request.QueryString["ID"] + "' Or ProductID ='" + Request.QueryString["ID"] + "'or '"+int.TryParse(Request.QueryString["PriceID"]<5000)+"'";// or ProductName='"+Request.QueryString["Name"]+"'";
// if (Request.QueryString["ID"] != "" && Request.QueryString["ID"] != null)
// {
// string query = "Select * from Products where ProductID= " + proid + " AND UnitCost < 5000";
// string query = "Select * from Products where ProductID= '" + Session["mysession"] + "' AND UnitCost < 5000";
// string query = "Select * from Products where ProductID= " +Session["mysession"] + " AND UnitCost < 5000";
if (Request.QueryString["ID"] != null && Request.QueryString["ID"].ToString() != "")
{
// string query = "Select * from Products where ProductID= " + Request.QueryString["ID"].ToString() + " AND UnitCost < 5000";
string query = "Select * from Products where ProductID= '" + Request.QueryString["ID"].ToString() +"' AND UnitCost < 5000";
//string query = "Select * from Products where ProductID= '" + Request.QueryString["ID"].ToString() + "' AND UnitCost < 5000";
//DataSet ds = new DataSet();
DataSet dss = obj.fillgrid(query);
GridView1.DataSource = dss.Tables[0];
GridView1.DataBind();
}
//}
//conn.Close();
}
我将loadgridview放在页面上load
i put loadgridview on page load
推荐答案
frnd
您可以按照以下代码编写逻辑
hi frnd
you can write you logic as per below code
string proid;
string querydr = "select * from Products";
SqlDataReader dr = obj.fillcomb(querydr);
while (dr.Read())
{
if(proid == String.empty)
{
proid = Convert.ToInt16(dr["ProductID"]);
}
else
{
proid +=","+Convert.ToInt16(dr["ProductID"])
}
}
Response.Redirect("your page name"?ID=proid);
并进入另一页:
and into another page:
if(Request.QueryString["ID"] !=null && Request.QueryString["ID"].toString() != "")
{
string query = "Select * from Products where ProductID= '" + Request.QueryString["ID"].ToString() + "' AND UnitCost < 5000"; //request.querystring should
}
让我知道这个解决方案对您有帮助.
let me know is this solution is help.
我正在提出一个建议.您可以通过逗号分隔来执行此操作.在主页上获取隐藏的变量.
I am giving one approch. You can do this by comma separate. Take hidden variable on main page.
input type="hidden" name="pdids" id="pdids" runat="server" />
在第一页中,您需要将ID附加到此隐藏变量中.
in page one you need to append ids to this hidden variable.
string querydr = "select * from Products";
SqlDataReader dr = obj.fillcomb(querydr);
string proid =null;
while (dr.Read())
{
proid += string.Format("{0}-", Convert.ToInt16(dr["ProductID"]));
}
pdids.Value=proid ;
在页面中,您将像波纹管一样访问它
In page to you will access it like bellow
if(!string.IsNullOREmpty(Request.QueryString["pdids"]))
{
string query = "Select * from Products where ProductID= '" + Request.QueryString["pdids"].ToString() + "' AND UnitCost < 5000";
}
您可以通过以下两种方法进行操作:
1)通过重定向字符串:
There are a couple of ways you can do it:
1) Via the redirect string:
www.mydomain.com/mypage?id1&id2&id3
2)通过Cookies
3)通过会话变量.
Google会告诉您如何使用它们.您的选择,但我可能会使用Session.
2) Via Cookies
3) Via Session variables.
Google will tell you how to use each of them. Your choice, but I would probably use the Session.
这篇关于在解决与查询字符串和响应有关的问题时令人困惑.redirct.(更新)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!