当前位置:编程学习 > asp >>

网上购物系统(Task008)——FormView编辑更新商品详细信息

一、前期准备

编辑商品信息属于管理功能,管理功能的网页最好单独放在一个文件夹中,为此,做一些准备工作:

1、修改母版页中的路径为绝对路径

2、复制Controls中的ItemDetailsControl.ascx,改名为ItemManageControl.ascx

3、在ItemManageControl.ascx中的FormView的ItemPlate模板中添加三个LinkButton按钮,编辑、新建、删除。设置一下单元格右对齐,会美观一点。

4、临时在ItemDetails.aspx中添加代码:

Response.Redirect("Manager/ItemManage.aspx" + Request.Url.Query);

5、Web中新建文件夹Manager,并添加ItemManage.aspx,引用母版页

二、编辑EditItemTemplate模板,可直接将模板ItemTemplate复制过来进行修改,添加必要的文本框、下拉列表框,模板代码如下:

(注意:<%@OutputCacheDuration="100000"VaryByParam="page;categoryId"%>页面缓存要去掉,否则,嘿嘿嘿)

[html]  <EditItemTemplate> 
    <table cellpadding="0" cellspacing="0"> 
        <tr> 
            <td height="18" width="18"> 
            </td> 
            <td height="18" width="96"> 
            </td> 
            <td height="18" width="18"> 
            </td> 
            <td height="18" width="96"> 
            </td> 
            <td height="18" width="180"> 
            </td> 
        </tr> 
        <tr> 
            <td style="height: 18px" width="18"> 
            </td> 
            <td rowspan="8" width="96"> 
                <asp:Image ID="imgItem" runat="server" AlternateText='<%# Eval("Name") %>' Height="144" 
                    ImageUrl='<%# Eval("Image") %>' Width="144" /></td> 
            <td style="height: 18px" width="18"> 
            </td> 
            <td colspan="2" style="height: 18px"> 
                <asp:FileUpload ID="fupImage" runat="server" Width="80%" /> 
                <asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="上传" /></td> 
        </tr> 
        <tr> 
            <td width="18"> 
            </td> 
            <td width="18"> 
            </td> 
            <td width="96"> 
                商品类别:</td> 
            <td width="180"> 
                <asp:DropDownList ID="ddlCategories" runat="server"  
                AutoPostBack="True"  
                OnSelectedIndexChanged="ddlCategories_SelectedIndexChanged"> 
                </asp:DropDownList> 
            </td> 
        </tr> 
        <tr> 
            <td width="18"> 
            </td> 
            <td width="18"> 
            </td> 
            <td width="96"> 
                商品名称:</td> 
            <td width="180"> 
                <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox> 
            </td> 
        </tr> 
        <tr> 
            <td width="18"> 
            </td> 
            <td width="18"> 
            </td> 
            <td width="96"> 
                商品价格:</td> 
            <td width="180"> 
                <asp:TextBox ID="txtPrice" runat="server" Text='<%# Bind("Price") %>'></asp:TextBox> 
            </td> 
&

补充:Web开发 , ASP.Net ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,