DataList实现编辑,删除,更新,取消,记录转存功能
来源:互联网 发布:国际数据调研公司 编辑:程序博客网 时间:2024/06/11 01:23
前台代码:
<div>
<asp:DataList ID="DataList1"runat="server" oneditcommand="DataList1_EditCommand"
onitemcommand="DataList1_ItemCommand"
oncancelcommand="DataList1_CancelCommand"
ondeletecommand="DataList1_DeleteCommand"
onupdatecommand="DataList1_UpdateCommand">
<EditItemTemplate>
<tablestyle="width:100%;">
<tr>
<td class="style2">
商品名:</td>
<td>
<asp:TextBox ID="TextBox1"runat="server" Text='<%# Eval("ProdctName")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
规格:</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"Text='<%# Eval("ProdctStandard") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
包装率:</td>
<td>
<asp:TextBox ID="TextBox3"runat="server" Text='<%# Eval("PackagingRatio")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
商品条码:</td>
<td>
<asp:TextBox ID="TextBox4"runat="server" Text='<%# Eval("ArticleNum")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
价格:</td>
<td>
<asp:TextBox ID="TextBox5"runat="server" Text='<%# Eval("Price")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Button ID="btnUpdate"runat="server" Text="更新"
CommandArgument='<%#Eval("PId") %>' CommandName="update" />
</td>
<td>
<asp:Button ID="btnCancel"runat="server" Text="取消" CommandName="Cancel"/>
</td>
</tr>
</table>
</EditItemTemplate>
<ItemTemplate>
产品名:<asp:LabelID="Label1" runat="server" Text='<%#Eval("ProdctName") %>'></asp:Label>
<br />
规格:<asp:LabelID="Label2" runat="server" Text='<%# Eval("ProdctStandard")%>'></asp:Label>
<br />
包装率:<asp:LabelID="Label3" runat="server" Text='<%#Eval("PackagingRatio") %>'></asp:Label>
<br />
商品条码:<asp:LabelID="Label4" runat="server" Text='<%#Eval("ArticleNum") %>'></asp:Label>
<br />
超市价格:<asp:LabelID="Label5" runat="server" Text='<%#Eval("Price") %>'></asp:Label>
<br />
<asp:ButtonID="btnedit" runat="server" CommandName="edit"Text="编辑" />
<asp:ButtonID="btndelete" runat="server"CommandName="delete"
Text="删除" CommandArgument='<%# Eval("PId") %>' />
<br />
<asp:ButtonID="Button3" runat="server" CommandArgument='<%#Eval("PId") %>'
CommandName="Buy" Height="22px" Text="放入购物车"Width="120px" />
</ItemTemplate>
</asp:DataList>
<br />
</div>
后台代码:
private void DataListBind()
{
string sql = "select * fromProduct";
DataTable dt =SqlHelper.ExecuteDataTable(sql);
this.DataList1.DataSource = dt;
DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source,DataListCommandEventArgs e)
{
if (e.CommandName == "Buy")
{
string ProName =(e.Item.FindControl("lblProductName") as Label).Text;
string ProStandarde =(e.Item.FindControl("lblProductStandard") as Label).Text;
string ProPackaging =(e.Item.FindControl("lblPackagingRatio") as Label).Text;
string ProArtialeNum =(e.Item.FindControl("lblArticleNum") as Label).Text;
string ProPrice =(e.Item.FindControl("lblPrice") as Label).Text;
string sql ="insert intoShoppingCart(ProductName,ProductStandard,PackagingRatio,ArticleNum,Price)values(@ProductName,@ProductStandard,@PackagingRatio,@ArticleNum,@Price)";
SqlParameter[] pms =new SqlParameter[] {
newSqlParameter("@ProductName",ProName),
newSqlParameter("@ProductStandard",ProStandarde),
new SqlParameter("@PackagingRatio",ProPackaging),
newSqlParameter("@ArticleNum",ProArtialeNum),
newSqlParameter("@Price",ProPrice)
};
SQLHelper.ExecuteNonQuery(sql, pms);
}
}
protected void DataList1_EditCommand(object source,DataListCommandEventArgs e)
{
this.DataList1.EditItemIndex =e.Item.ItemIndex;
DataListBind();
}
protected void DataList1_UpdateCommand(objectsource, DataListCommandEventArgs e)
{
stringname=(e.Item.FindControl("TextBox1") as TextBox).Text.Trim();
stringStand=(e.Item.FindControl("TextBox2") as TextBox).Text.Trim();
stringratio=(e.Item.FindControl("TextBox3") as TextBox).Text.Trim();
stringnum=(e.Item.FindControl("TextBox4") as TextBox).Text.Trim();
stringprice=(e.Item.FindControl("TextBox5") as TextBox).Text.Trim();
string sql = "update Product setProdctName=@name,ProdctStandard=@standard,PackagingRatio=@ratio,ArticleNum=@num,Price=@pricewhere PId=@id";
SqlParameter[] prm = newSqlParameter[]{
newSqlParameter("name",name), newSqlParameter("standard",Stand), newSqlParameter("ratio",ratio),
newSqlParameter("num",num),new SqlParameter("price",price),newSqlParameter("id",e.CommandArgument)
};
SqlHelper.ExecuteNonQuery(sql,prm);
}
protected void DataList1_CancelCommand(objectsource, DataListCommandEventArgs e)
{
this.DataList1.EditItemIndex = -1;
DataListBind();
}
protected void DataList1_DeleteCommand(objectsource, DataListCommandEventArgs e)
{
string sql = "delete fromProduct where PId=@id";
SqlHelper.ExecuteNonQuery(sql,newSqlParameter("id",e.CommandArgument));
DataListBind();
}
- DataList实现编辑,删除,更新,取消,记录转存功能
- DataList实现编辑,删除,更新,取消,记录转存功能
- 使用DataList实现 加入购物车,编辑,删除,更新,取消功能
- ASP.NET中运用DataList控件来实现编辑、更新、删除、取消等功能
- 使用DataList实现 加入购物车,编辑,删除,更新,取消功能。要求连一个产品表。
- 使用DataList实现 加入购物车,编辑,删除,更新,取消功能。
- DataList编辑、更新、取消、删除、分页
- DataList编辑、更新、取消、删除、分页
- DataList编辑、更新、取消、删除、分页
- DataList编辑、更新、取消、删除、分页
- DataList编辑、更新、取消、删除、分页
- 模拟网易邮箱实现全选,全不的功能/使用DataList实现 加入购物车,编辑,删除,更新,取消功能。/试完成Datalist使用存储过程来分页
- 使用gridview实现编辑、更新、取消功能和删除功能
- 1模拟网易邮箱实现全选,全不的功能(服务端和客户端) 2 使用DataList实现 加入购物车,编辑,删除,更新,取消功能。要求连一个产品表。
- GridView的编辑,更新,取消,删除等功能演示
- DataList编辑、更新、取消、删除、分页(分页控件AspNetPager.dll)
- 实现DataList的编辑功能
- dataGrid 编辑 更新 删除 取消
- java中的深拷贝和浅拷贝
- 309. Best Time to Buy and Sell Stock with Cooldown
- ProgressFragment的简单封装
- How to install Homebrew, OpenCV and Python for OS X El Capitan (10.11)
- 309. Best Time to Buy and Sell Stock with Cooldown
- DataList实现编辑,删除,更新,取消,记录转存功能
- 《算法竞赛入门经典》习题——Chapter 1
- 本地机器ping不通虚拟机解决方案
- atoi()函数
- 【Dubbo入门】——基础知识篇
- 深入理解JVM笔记
- 使用卷积神经网络区分猫和狗.md
- codewar c++ 8分题(2))
- Driver:搭建linux驱动开发环境、内核驱动开发基础、导出符号、打印优先级