与查询字符串相关的任务出现逻辑编码错误 [英] logical coding error with my task related to querystring

查看:67
本文介绍了与查询字符串相关的任务出现逻辑编码错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正打算将产品ID从主页重定向到productcatalog.aspx页,以根据主页和价格范围的productid在网格中显示一些产品..
但是我在gridview中什么也没得到..

这是主页中的代码

i am tring to redirect the product ids from main page to productcatalog.aspx page to show some that in a grid on the base of productid from main page and price range..
but i am getting nothing in gridview..

here is the code in main page

dbcon obj = new dbcon();
public string proid;

  protected void Page_Load(object sender, EventArgs e)
  {




  }

  protected void LinkButton4_Click(object sender, EventArgs e)
  {
      //string proid;

         string querydr = "select * from Products";
         SqlDataReader dr = obj.fillcomb(querydr);

          while (dr.Read())
          {

              if(proid != String.Empty)
                {
               proid = dr["ProductID"].ToString();
               }
            else
               {
                   proid += "," + Convert.ToInt16(dr["ProductID"]);
              }


              }



     Response.Redirect("ProductCatalog.aspx?ID="+proid);



并在productcatalog.aspx页面上.调整productcatalog.aspx页面加载的功能



and on productcatalog.aspx page.. i am have the fallwing code. caling the fuction on page load of productcatalog.aspx

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




在网址中,我得到了




and in url i am getting

http://localhost:54681/myfinalproject/ProductCatalog.aspx?ID=65



问题出在哪里.



where is the problem.

推荐答案

hi farroqspecials

您必须在以下条件下进行更改

hi farroqspecials

you have to change below condition

if(proid == String.Empty)



请让我知道这是否适合您



Please let me know if this is work for you


检查此博客
使用QueryString在页面之间传递变量 [
check this blog
Passing variables between pages using QueryString[^]
--NDK


请先检查您在页面上是否获得ID的天气.如果是,则检查产品表的ProductID列是nvarchar类型还是数字.

因为我认为您正在表中传递字符串ID,并且它是数字类型,所以类型不匹配.

first check weather you are getting id on your page or not. if yes then check ProductID column of product table is of nvarchar type or numeric.

Because i think that you are passing string ID in table and that is of numeric type so there is mismatch of type.

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


希望对您有帮助.
如果有帮助,请不要忘记将其标记为答案. :)


Hope this will help you.
Don''t forget to mark as answer if it helps. :)


这篇关于与查询字符串相关的任务出现逻辑编码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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