Order-Related Modules for an ASP.NET AJAX Server-Centric Based Online Shopping Website - More Behind the Scenes Code
(Page 3 of 7 )
Second, we've leveraged one of the important triggers, AsyncPostBackTrigger,to invoke the updating action of the UpdatePanelcontrol. The following shows the related code:
private void BindProductData(int nCategoryID){
///define the class that gets the data
Product product = new Product();
SqlDataReader dr = product.GetProductByCategory(nCategoryID);
///Set the control's data source
ProductView.DataSource = dr;
///bind data to the control
ProductView.DataBind();
///Close the database connection
dr.Close();
}
......
protected void ProductList_ItemCommand(object source, DataListCommandEventArgs e){
BindProductData(Int32.Parse(e.CommandArgument.ToString()));
}
Here we have already provided detailed comments. As you see, the general routine of the code is like those arranged in the previous modules. Here, the "ProductView" control corresponds to the ASP.NET GridView to display the selected goods, while the "ProductList" refers to the ASP.NET control named DataList to show the product category.
For now, acute readers may have already detected a secret. Here, again, we list the related code:
<a href='../Admin/Product/ProductInfo.aspx?ProductID=<%# DataBinder.Eval(Container.DataItem,"ProductID")%>' target="_blank">
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px">
<asp:Image ID="ProductPicture" Runat="server" Width="90" Height="120" ImageUrl='<%# Eval("PictureID", "../Handler.ashx?Id={0}") %>' > </asp:Image>
</asp:Panel></a>
How can we display the images within the database? As the previous sections mentioned, we use a field of the "image" type to directly store the binary image data into the table. In earlier ASP.NET solutions, it is very difficult to show an image at the specified position on a web page, especially as the image data is persisted into the database table. Another commonly-used way to deal with image data is to independently store the image files while only their related paths are in the table. Each solution has its own pros and cons.
Next: Web Handler >>
More ASP.NET Articles
More By Xianzhong Zhu