知识大全 FormView编辑更新商品详细信息
Posted 商品
篇首语:人生必须的知识就是引人向光明方面的明灯。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 FormView编辑更新商品详细信息相关的知识,希望对你有一定的参考价值。
FormView编辑更新商品详细信息 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
一 前期准备 编辑商品信息属于管理功能 管理功能的网页最好单独放在一个文件夹中 为此 做一些准备工作 修改母版页中的路径为绝对路径 复制Controls中的ItemDetailsControl ascx 改名为ItemManageControl ascx 在ItemManageControl ascx中的FormView的ItemPlate模板中添加三个LinkButton按钮 编辑 新建 删除 设置一下单元格右对齐 会美观一点 临时在ItemDetails aspx中添加代码 Response Redirect( Manager/ItemManage aspx + Request Url Query) Web中新建文件夹Manager 并添加ItemManage aspx 引用母版页 二 编辑EditItemTemplate模板 可直接将模板ItemTemplate复制过来进行修改 添加必要的文本框 下拉列表框 模板代码如下 (注意 <%@OutputCacheDuration= VaryByParam= page;categoryId %>页面缓存要去掉 否则 嘿嘿嘿) [] <EditItemTemplate> <table cellpadding= cellspacing= > <tr> <td height= width= > </td> <td height= width= > </td> <td height= width= > </td> <td height= width= > </td> <td height= width= > </td> </tr> <tr> <td width= > </td> <td rowspan= width= > <asp:Image ID= imgItem runat= server AlternateText= <%# Eval( Name ) %> Height= ImageUrl= <%# Eval( Image ) %> Width= /></td> <td width= > </td> <td colspan= > <asp:FileUpload ID= fupImage runat= server Width= % /> <asp:Button ID= btnUpload runat= server OnClick= btnUpload_Click Text= 上传 /></td> </tr> <tr> <td width= > </td> <td width= > </td> <td width= > 商品类别 </td> <td width= > <asp:DropDownList ID= ddlCategories runat= server AutoPostBack= True OnSelectedIndexChanged= ddlCategories_SelectedIndexChanged > </asp:DropDownList> </td> </tr> <tr> <td width= > </td> <td width= > </td> <td width= > 商品名称 </td> <td width= > <asp:TextBox ID= txtName runat= server Text= <%# Bind( Name ) %> ></asp:TextBox> </td> </tr> <tr> <td width= > </td> <td width= > </td> <td width= > 商品价格 </td> <td width= > <asp:TextBox ID= txtPrice runat= server Text= <%# Bind( Price ) %> ></asp:TextBox> </td> </tr> <tr> <td width= > </td> <td width= > </td> <td width= > 商品描述 </td> <td width= > <asp:TextBox ID= txtDescn runat= server Text= <%# Bind( Descn ) %> ></asp:TextBox> </td> </tr> <tr> <td width= > </td> <td width= > </td> <td width= > 供应时间 </td> <td width= > <asp:TextBox ID= txtSupplyTime runat= server Text= <%# Bind( SupplyTime ) %> ></asp:TextBox> </td> </tr> <tr> <td width= > </td> <td width= > </td> <td width= > 供应日期 </td> <td width= > <asp:TextBox ID= txtSupplyDate runat= server Text= <%# Bind( SupplyDate ) %> ></asp:TextBox> </td> </tr> <tr> <td width= > </td> <td width= > </td> <td width= > 供应地区 </td> <td width= > <asp:TextBox ID= txtSupplyArea runat= server Text= <%# Bind( SupplyArea ) %> ></asp:TextBox> </td> </tr> <tr> <td height= width= > </td> <td height= width= > </td> <td height= width= > </td> <td height= width= > </td> <td height= width= align= right > <asp:LinkButton ID= lbtnDelete runat= server CommandName= Update Text= 更新 /> <asp:LinkButton ID= lbtnNew runat= server CommandName= Cancel Text= 取消 /> </td> </tr> </table> </EditItemTemplate> <EditItemTemplate> <table cellpadding= cellspacing= > <tr> <td height= width= > </td> <td height= width= > </td> <td height= width= > </td> <td height= width= > </td> <td height= width= > </td> </tr> <tr> <td width= > </td> <td rowspan= width= > <asp:Image ID= imgItem runat= server AlternateText= <%# Eval( Name ) %> Height= ImageUrl= <%# Eval( Image ) %> Width= /></td> <td width= > </td> <td colspan= > <asp:FileUpload ID= fupImage runat= server Width= % /> <asp:Button ID= btnUpload runat= server OnClick= btnUpload_Click Text= 上传 /></td> </tr> <tr> <td width= > </td> <td width= > </td> <td width= > 商品类别 </td> <td width= > <asp:DropDownList ID= ddlCategories runat= server AutoPostBack= True OnSelectedIndexChanged= ddlCategories_SelectedIndexChanged > </asp:DropDownList> </td> </tr> <tr> <td width= > </td> <td width= > </td> <td width= > 商品名称 </td> <td width= > <asp:TextBox ID= txtName runat= server Text= <%# Bind( Name ) %> ></asp:TextBox> </td> </tr> <tr> <td width= > </td> <td width= > </td> <td width= > 商品价格 </td> <td width= > <asp:TextBox ID= txtPrice runat= server Text= <%# Bind( Price ) %> ></asp:TextBox> </td> </tr> <tr> <td width= > </td> <td width= > </td> <td width= > 商品描述 </td> <td width= > <asp:TextBox ID= txtDescn runat= server Text= <%# Bind( Descn ) %> ></asp:TextBox> </td> </tr> <tr> <td width= > </td> <td width= > </td> <td width= > 供应时间 </td> <td width= > <asp:TextBox ID= txtSupplyTime runat= server Text= <%# Bind( SupplyTime ) %> ></asp:TextBox> </td> </tr> <tr> <td width= > </td> <td width= > </td> <td width= > 供应日期 </td> <td width= > <asp:TextBox ID= txtSupplyDate runat= server Text= <%# Bind( SupplyDate ) %> ></asp:TextBox> </td> </tr> <tr> <td width= > </td> <td width= > </td> <td width= > 供应地区 </td> <td width= > <asp:TextBox ID= txtSupplyArea runat= server Text= <%# Bind( SupplyArea ) %> ></asp:TextBox> </td> </tr> <tr> <td height= width= > </td> <td height= width= > </td> <td height= width= > </td> <td height= width= > </td> <td height= width= align= right > <asp:LinkButton ID= lbtnDelete runat= server CommandName= Update Text= 更新 /> <asp:LinkButton ID= lbtnNew runat= server CommandName= Cancel Text= 取消 /> </td> </tr> </table> </EditItemTemplate> 三 ItemManageControl ascx的后台代码 代码页的主任是读取前台窗体的值 主要是FileUpload控件和DropDownList控件的值 两个值 分别使用了ViewState存储了信息 读取数据的时候 注意 如果用户没有做修改 刚使用原来的值 这个值放在了privatestaticIList<ItemDetails> itemdetails =newList<ItemDetails>() 中 [csharp] using System; using System Web; using System Web UI WebControls; using System Collections Generic; using WestGarden DAL; using WestGarden Model; namespace WestGarden Web public partial class ItemManageControl : System Web UI UserControl private static IList<ItemDetails> itemdetails = new List<ItemDetails>() protected void Page_Load(object sender EventArgs e) if (!IsPostBack) BindFormView() ViewState[ ImageUrl ] = null; ViewState[ SelectedCategoryId ] = null; protected void fvwItemDetails_ModeChanging(object sender FormViewModeEventArgs e) switch (e NewMode) case FormViewMode Edit: this fvwItemDetails ChangeMode(FormViewMode Edit) BindFormView() DropDownList ddl = (DropDownList)fvwItemDetails FindControl( ddlCategories ) BindDropDownList(ddl) break; case FormViewMode ReadOnly: this fvwItemDetails ChangeMode(FormViewMode ReadOnly) BindFormView() break; default: break; protected void fvwItemDetails_PreRender(object sender EventArgs e) protected void ddlCategories_SelectedIndexChanged(object sender EventArgs e) DropDownList ddl = (DropDownList)fvwItemDetails FindControl( ddlCategories ) ViewState[ SelectedCategoryId ] = ddl SelectedValue; protected void btnUpload_Click(object sender EventArgs e) FileUpload fup = (FileUpload)fvwItemDetails FindControl( fupImage ) if (fup HasFile) fup SaveAs(Server MapPath( ~/Images/Items/ ) + fup FileName) Image img = (Image)fvwItemDetails FindControl( imgItem ) img ImageUrl = ~/Images/Items/ + fup FileName ToString() ViewState[ ImageUrl ] = ~/Images/Items/ + fup FileName ToString() else Response Write( <script>alert( 请先浏览并选择图片 )</script> ) protected void fvwItemDetails_ItemUpdating(object sender FormViewUpdateEventArgs e) if (ViewState[ ImageUrl ] != null) itemdetails[ ] Image = ViewState[ ImageUrl ] ToString() if (ViewState[ SelectedCategoryId ] != null) DropDownList ddl = (DropDownList)fvwItemDetails FindControl( ddlCategories ) itemdetails[ ] CategoryId = ViewState[ SelectedCategoryId ] ToString() TextBox txtname = (TextBox)fvwItemDetails FindControl( txtName ) itemdetails[ ] Name = txtname Text; TextBox txtPrice = (TextBox)fvwItemDetails FindControl( txtPrice ) itemdetails[ ] Price = decimal Parse(txtPrice Text) TextBox txtDescn = (TextBox)fvwItemDetails FindControl( txtDescn ) itemdetails[ ] Descn = txtDescn Text; TextBox txtSupplyTime = (TextBox)fvwItemDetails FindControl( txtSupplyTime ) itemdetails[ ] SupplyTime = txtSupplyTime Text; TextBox txtSupplyDate = (TextBox)fvwItemDetails FindControl( txtSupplyDate ) itemdetails[ ] SupplyDate = txtSupplyDate Text; TextBox txtSupplyArea = (TextBox)fvwItemDetails FindControl( txtSupplyArea ) itemdetails[ ] SupplyArea = txtSupplyArea Text; Item item = new Item() item UpdateItem(itemdetails[ ]) fvwItemDetails ChangeMode(FormViewMode ReadOnly) BindFormView() ViewState[ ImageUrl ] = null; ViewState[ SelectedCategoryId ] = null; private void BindFormView() int itemKey = int Parse(Request QueryString[ itemId ]) Item item = new Item() itemdetails = item GetItemDetailsByItemId(itemKey) fvwItemDetails DataSource = itemdetails; fvwItemDetails DataBind() private void BindDropDownList(DropDownList ddl) ddl DataSource = new Category() GetCategories() ddl DataTextField = Name ; ddl DataValueField = CategoryId ; ddl DataBind() string selectcategory = Request QueryString[ categoryId ] ToString() if (selectcategory != null) ListItem selectedItem = ddl Items FindByValue(selectcategory) if (selectedItem != null) selectedItem Selected = true; using System; using System Web; using System Web UI WebControls; using System Collections Generic; using WestGarden DAL; using WestGarden Model; namespace WestGarden Web public partial class ItemManageControl : System Web UI UserControl private static IList<ItemDetails> itemdetails = new List<ItemDetails>() protected void Page_Load(object sender EventArgs e) if (!IsPostBack) BindFormView() ViewState[ ImageUrl ] = null; ViewState[ SelectedCategoryId ] = null; protected void fvwItemDetails_ModeChanging(object sender FormViewModeEventArgs e) switch (e NewMode) case FormViewMode Edit: this fvwItemDetails ChangeMode(FormViewMode Edit) BindFormView() DropDownList ddl = (DropDownList)fvwItemDetails FindControl( ddlCategories ) BindDropDownList(ddl) break; case FormViewMode ReadOnly: this fvwItemDetails ChangeMode(FormViewMode ReadOnly) BindFormView() break; default: break; protected void fvwItemDetails_PreRender(object sender EventArgs e) protected void ddlCategories_SelectedIndexChanged(object sender EventArgs e) DropDownList ddl = (DropDownList)fvwItemDetails FindControl( ddlCategories ) ViewState[ SelectedCategoryId ] = ddl SelectedValue; protected void btnUpload_Click(object sender EventArgs e) FileUpload fup = (FileUpload)fvwItemDetails FindControl( fupImage ) if (fup HasFile) fup SaveAs(Server MapPath( ~/Images/Items/ ) + fup FileName) Image img = (Image)fvwItemDetails FindControl( imgItem ) img ImageUrl = ~/Images/Items/ + fup FileName ToString() ViewState[ ImageUrl ] = ~/Images/Items/ + fup FileName ToString() else Response Write( <script>alert( 请先浏览并选择图片 )</script> ) protected void fvwItemDetails_ItemUpdating(object sender FormViewUpdateEventArgs e) if (ViewState[ ImageUrl ] != null) itemdetails[ ] Image = ViewState[ ImageUrl ] ToString() if (ViewState[ SelectedCategoryId ] != null) DropDownList ddl = (DropDownList)fvwItemDetails FindControl( ddlCategories ) itemdetails[ ] CategoryId = ViewState[ SelectedCategoryId ] ToString() TextBox txtname = (TextBox)fvwItemDetails FindControl( txtName ) itemdetails[ ] Name = txtname Text; TextBox txtPrice = (TextBox)fvwItemDetails FindControl( txtPrice ) itemdetails[ ] Price = decimal Parse(txtPrice Text) TextBox txtDescn = (TextBox)fvwItemDetails FindControl( txtDescn ) itemdetails[ ] Descn = txtDescn Text; TextBox txtSupplyTime = (TextBox)fvwItemDetails FindControl( txtSupplyTime ) itemdetails[ ] SupplyTime = txtSupplyTime Text; TextBox txtSupplyDate = (TextBox)fvwItemDetails FindControl( txtSupplyDate ) itemdetails[ ] SupplyDate = txtSupplyDate Text; TextBox txtSupplyArea = (TextBox)fvwItemDetails FindControl( txtSupplyArea ) itemdetails[ ] SupplyArea = txtSupplyArea Text; Item item = new Item() item UpdateItem(itemdetails[ ]) fvwItemDetails ChangeMode(FormViewMode ReadOnly) BindFormView() ViewState[ ImageUrl ] = null; ViewState[ SelectedCategoryId ] = null; private void BindFormView() int itemKey = int Parse(Request QueryString[ itemId ]) Item item = new Item() itemdetails = item GetItemDetailsByItemId(itemKey) fvwItemDetails DataSource = itemdetails; fvwItemDetails DataBind() private void BindDropDownList(DropDownList ddl) ddl DataSource = new Category() GetCategories() ddl DataTextField = Name ; ddl DataValueField = CategoryId ; ddl DataBind() string selectcategory = Request QueryString[ categoryId ] ToString() if (selectcategory != null) ListItem selectedItem = ddl Items FindByValue(selectcategory) if (selectedItem != null) selectedItem Selected = true; 四 数据访问层DAL中的Item cs类中添加更新函数UpdateItem() 代码如下 [csharp] public void UpdateItem(ItemDetails item) SqlParameter[] parms; parms = new SqlParameter[] new SqlParameter( @ItemId SqlDbType Int) new SqlParameter( @CategoryId SqlDbType VarChar ) new SqlParameter( @Name SqlDbType VarChar ) new SqlParameter( @Price SqlDbType Decimal ) new SqlParameter( @Image SqlDbType VarChar ) new SqlParameter( @Descn SqlDbType VarChar ) new SqlParameter( @SupplyTime SqlDbType VarChar ) new SqlParameter( @SupplyDate SqlDbType VarChar ) new SqlParameter( @SupplyArea SqlDbType VarChar ) ; parms[ ] Value = item ItemId; parms[ ] Value = item CategoryId; parms[ ] Value = item Name; parms[ ] Value = item Price; parms[ ] Value = item Image; parms[ ] Value = item Descn; parms[ ] Value = item SupplyTime; parms[ ] Value = item SupplyDate; parms[ ] Value = item SupplyArea; SqlHelper ExecuteNonQuery(SqlHelper ConnectionStringLocalTransaction CommandType Text SQL_UPDATE_ITEM parms) cha138/Article/program/net/201311/13076相关参考
知识大全 百度百科里修改词条必须要填写修改原因的详细原因是什么
百度百科里修改词条必须要填写修改原因的详细原因是什么?修改词条时应填写修改原因,并指出修改的内容。修改原因应明确、准确、客观。标准的修改原因可以让编辑者以及浏览者方便地找到词条内容的更新理由以及具体位
问问商城的商品是礼拜几更新上架来着?货架都空了撒。。。从2009年3月3日起问问商城兑换的QB礼品,于每周二15:00整准时更新上架,(很精确的时间点)正所谓先下手为强,兑换先到先得,放的QB数量不多
想学习百度百科的编辑,请问在哪里可以详细的学会:tieba.baidu./p/2816123122:tieba.baidu./p/3818067686具体的学下你可以自己尝试编辑,或者参与百度百科导师
知识大全 7.4.4 DetaiIsView和FormView控件[1]
7.4.4DetaiIsView和FormView控件[1] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看
知识大全 7.4.4 DetaiIsView和FormView控件[2]
7.4.4DetaiIsView和FormView控件[2] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看
知识大全 JavaScript获取FCK编辑器信息的具体方法
JavaScript获取FCK编辑器信息的具体方法 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!这
cha138/Article/program/net/201311/14358
信息商品具有价值量的不可比性的原因在于信息商品具有_____。A、单件性特征B、知识性的性质C、价值转移的不确定性D、共享性的特征答案:A解析:信息商品具有价值量的不可比性,因为信息商品具有单件性的特
知识大全 在中国建筑人才网上找工作,怎么才能够确定信息的更新呢
在中国建筑人才网上找工作,怎么才能够确定信息的更新呢?可以先投简历过去看看,也可以打电话过去确认啊在中国建筑人才网合作的话做广告的价值在哪里?一般来说在网站上做广告,第一是提升品牌知明度,让更多的精英
知识大全 手机号码换了想在微信朋友圈发一条动态,让朋友们给我发条信息,怎么编辑好会特别一点
手机号码换了想在微信朋友圈发一条动态,让朋友们给我发条信息,怎么编辑好会特别一点?寂寞的夜里,或许你需要我的安慰请记得,午夜服务热线:人在江湖走换号经常有这个是的新号码那个寿终正寝了那号码忘火星了,这