在基于request.querystring的gridview中显示数据的问题 [英] problem in showing data in gridview on the base of request.querystring

查看:55
本文介绍了在基于request.querystring的gridview中显示数据的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我有一个问题,要通过查询字符串将ProductIds从主页获取到Product Catalog.aspx页面.
现在,当我在编码中进行一些更改时,如下所示.我将ProductsIDs表单的首页获取到了queryString.I,使用调试器进行了检查.在主页上,我进行了一些轻松的更改.现在ID将转到productcatalog.aspx页面.


First i have a problem of getting the ProductIds from main page to Product Catalog.aspx Page through querystring.
Now when i make some Changes in the coding as below. i am getting the ProductsIDs form main page to ProductCatalog.aspx page thorugh querystring.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()
   {


       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();
       }

   }



我将loadgridview放在页面上load



i put loadgridview on page load

推荐答案



查询应该是这样.我希望它可以工作..

query =从(63,64,65)中的ProductID并且UnitCost <5000的产品中选择*"
Hi,

Query should be like this.i hope it will work..

query = "Select * from Products where ProductID in (63,64,65) AND UnitCost < 5000"


在sql中使用split()并拆分prodID并进行查询:

字符串Query =从产品ID在其中的产品中选择*(从dbo.split(``* * + Request.QueryString [" ID].ToString()+"'',``,'')中选择*)AND UnitCost< ; 5000;

使用上面的查询,它将给出您的结果.
Use split() in sql and split prodID and make query :

string Query = "Select * from Products where ProductID in (Select * from dbo.split( ''" + Request.QueryString["ID"].ToString() +"'', '','')) AND UnitCost < 5000";

Use above query, it will give your result.


您好,

您生成的查询是错误的

查询应这样生成

Hi,

Your query generated is wrong

Query should be generated like this

query	"Select * from Products where ProductID in (''63,64,65'') AND UnitCost < 5000"



希望这会有所帮助:)

谢谢
Vinod



Hope this will help :)

Thanks
Vinod


这篇关于在基于request.querystring的gridview中显示数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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