private void BindData()
{
string sStr;
// 判斷是 商品快速查詢 還是分類查詢
if (Request.Params["sStr"] != null)
{
// 如果是 商品快速查詢
//if else (1.運用條件來顯示商品的頁面2.查詢商品的條件無效,請重試)
sStr = Request.Params["sStr"];//task out CategoryId about shopping
if (sStr.Length > 0)
{
string sSQL = "SELECT O.*, S.Name AS CategoryName, P.Name AS Vendor FROM dbo.Products O INNER JOIN dbo.Categories S ON O.CategoryID = S.ID INNER JOIN dbo.Customers P ON O.VendorID = P.ID WHERE O.ModelNumber LIKE '%" + sStr + "%' OR O.ModelName LIKE '%" + sStr + "%' OR O.Description LIKE '%" + sStr + "%' ORDER BY O.ModelName, O.ModelNumber";
pub.Fill(sSQL);
this.DisPage1.Open(pub.DataSet1);
}
else
{
pub.sTitle = pub.sTitle + " -- 商品查詢 -- 指定查詢條件, 至少要輸入1個字符";
DisPage1.Visible = false;
}
}
else if (Request.Params["CategoryID"] != null)
{
//1.take out CategoryId
//2.judge categoryId char anything here
sStr = Request.Params["CategoryID"];
//if struck (1.browser all shopping 2.no shopping display)
if (Int32.Parse(sStr) >= 0)
{
int iID = int.Parse(sStr);
string sSQL = "SELECT O.*, S.Name AS CategoryName, P.Name AS Vendor FROM dbo.Products O INNER JOIN dbo.Categories S ON O.CategoryID = S.ID INNER JOIN dbo.Customers P ON O.VendorID = P.ID WHERE O.CategoryID = " + iID + " ORDER BY O.ModelName, O.ModelNumber";
//數據庫的連結和庫的添充都是在FILL 方法中進行的
pub.Fill(sSQL);
//public DataSet DataSet1;
this.DisPage1.Open(pub.DataSet1);
pub.sTitle = pub.sTitle + " -- 商品瀏覽 -- 所有 " + Request.Params["CategoryName"].ToString() + " 的商品";
}
else
{
pub.sTitle = pub.sTitle + " -- 商品瀏覽 -- 指定查詢條件無效";
DisPage1.Visible = false;
}
lbMsg.Text = pub.sTitle;//display massage about shopping here
}
else
Response.Redirect("Error.aspx?sStr=非法頁面訪問", true);
}
<cc1:dispage id="DisPage1" runat="server" PageSize="16" PageTitleBorder="None" TitleBorderWidth="1px" TitleBorderColor="Gainsboro" PageTitleColor="224, 224, 224" TitleState="Bottom" PageGroup="3" BorderWidth="1px" BackColor="Transparent" BorderStyle="None" BorderColor="#FFFFC0" Width="98%" ForeColor="Black">
<DataTemplate>
<asp:DataList id="DataList1" RepeatColumns="4" runat="server" Width="100%" BorderColor="#CC9966" BorderStyle="None" BackColor="White" CellPadding="4" GridLines="Both" BorderWidth="1px" ShowHeader="False" ShowFooter="False" RepeatDirection="Horizontal">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<AlternatingItemStyle BackColor="Snow"></AlternatingItemStyle>
<ItemStyle ForeColor="#330099" BorderStyle="Dashed" BackColor="White"></ItemStyle>
<ItemTemplate>
<TABLE cellSpacing="0" cellPadding="0" width="100%" align="center" border="0">
<TR>
<TD vAlign="top" align="middle"><A href='<%# "Product.aspx?ProductID=" + DataBinder.Eval(Container.DataItem, "ProductID").ToString() + "&CategoryID=" + DataBinder.Eval(Container.DataItem, "CategoryID").ToString() %>' title=點擊查看明細 target=P>
<IMG src='ProductImages/<%# DataBinder.Eval(Container.DataItem, "ProductImage") %>' border=0 width=100px height=100px>
<br>
<%# DataBinder.Eval(Container.DataItem, "ModelNumber") %>
-
<%# DataBinder.Eval(Container.DataItem, "ModelName") %>
<br>
<FONT color="silver">
<DEL>
<%# DataBinder.Eval(Container.DataItem, "UnitCost", "{0:c}") %>
</DEL>
</FONT>
<br>
<FONT color="coral">
<%# DataBinder.Eval(Container.DataItem, "Discount", "{0:c}") %>
</FONT></A>
<br>
<%# DataBinder.Eval(Container.DataItem, "Vendor") %>
<a href='AddToCart.aspx?ProductID=<%# DataBinder.Eval(Container.DataItem, "ProductID") %>' target=A><img src="Images/ShoppingCart.gif" border="0" title="點擊訂單此商品"></a>
</TD>
</TR>
</TABLE>
</ItemTemplate>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
</asp:DataList>
</DataTemplate>
</cc1:dispage>