在查询字符串中传递多个值(循环)的问题 [英] problem for passing more than one value(looping) in querystring

查看:66
本文介绍了在查询字符串中传递多个值(循环)的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在查询字符串中使用多个值..下面的代码在网格中仅显示一种产品..这是错误的结果

这是我的main.aspx页面上的代码

how to pas more than one value in querystring.. the code below show only one product in a grid.. which is a wrong result

here is the code on my main.aspx page

protected void LinkButton4_Click(object sender, EventArgs e)
   {


                     string querydr = "select * from Products";
           SqlDataReader dr = obj.fillcomb(querydr);
           while (dr.Read())
           {
                proid = Convert.ToInt16(dr["ProductID"]); // what changes i have to make to make it work correctly
                Response.Redirect("ProductCatalog.aspx?ID=" + proid);


           }


       }

   }



这是我的productcatalog.aspx页面上的页面



and here is the page on my productcatalog.aspx page

if (Request.QueryString["ID"] != "" && Request.QueryString["ID"] != null)
       {
           string query = "Select * from Products where ProductID= " + Convert.ToInt32(Request.QueryString["ID"].ToString()) + " AND UnitCost < 5000";
                      DataSet ds = obj.fillgrid(query);
           GridView1.DataSource = ds.Tables[0];
           GridView1.DataBind();
       }

推荐答案

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 &lt; 5000"; //request.querystring should
}



让我知道这个解决方案对您有帮助.



let me know is this solution is help.


您好,

挑衅地它会向您显示所有记录中的一条记录,原因是单击按钮时 Response.Redirect .

当您单击LinkBut​​ton4时,它将从Response.Redirect行重定向页面,因此其他代码将不会执行.

看一下 Response.Redirect 的行为.

您需要更改逻辑.

希望这可以帮助您解决问题,

谢谢
-amit.
Hi,

defiantly it will show you one record from all your records, reason is Response.Redirect in your button click.

when you click on LinkButton4 it will redirect your page from Response.Redirect line so other code will not execute.

have a look at behavior of Response.Redirect.

you need to change your logic.

hope this will help you to resolving problem,

thanks
-amit.


这篇关于在查询字符串中传递多个值(循环)的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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