我有一个 Web 应用程序,它包含一个包含两个 url 的页面,当单击它们时,它们根据供应商 ID 分别将产品显示到 Northwind DB 的 Products 表中的另一个页面上。使用文字控件时一切正常,但是,在试验中,我将文字控件更改为 Gridview,现在我没有列出所有相应的产品,而是得到一个仅显示相应供应商 ID 组的最后一个产品的列。例如
结果:项目:Chang ...有人可以指出我做错了什么/失踪的方向。这是我的代码
/******** Hypertext (page with the URLs):
<div>
<div><a href="gridtest.aspx?orderList=1">Supplier ID 1</a> </div>
<div><a href="gridtest.aspx?orderList=2">Supplier ID 2</a> </div>
</div>
/******** Hypertext (page with the Gridview):
<asp:GridView ID="gvSupplies" runat="server">
</asp:GridView>
/********* code behind gridview page:
protected void Page_Load(object sender, EventArgs e)
{
// Retrieve the connection string stored in the Web.config file.
String connectionString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
string mySQLQuery = null;
string vID = Request.QueryString["orderList"];
mySQLQuery = "SELECT SupplierID, ProductName, UnitPrice, UnitsOnOrder FROM Products WHERE (SupplierID = SupplierID) AND SupplierID ='" + vID + "' ORDER BY ProductName ";
SqlCommand myCommand = new SqlCommand(mySQLQuery, connection);
SqlDataReader myReader1 = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
while ((myReader1.Read()))
{
gvSupplies.DataSource = myReader1.GetString(1) + " " + myReader1.GetValue(2);
gvSupplies.DataBind();
}
connection.Close();
}