datalist控件ItemCommand与DataList1_ItemDataBound编程实例,使用示例数据库
2010-01-30 00:21
435 查看
前台代码
后台
<form id="form1" runat="server"> <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"> </asp:Repeater> <asp:DataList ID="DataList1" runat="server" DataKeyField="ProductID" DataSourceID="SqlDataSource1" OnItemCommand="DataList1_ItemCommand" OnItemDataBound="DataList1_ItemDataBound"> <ItemTemplate> ProductID: <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>'></asp:Label><br /> ProductName: <asp:Label ID="ProductNameLabel" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label><br /> SupplierID: <asp:Label ID="SupplierIDLabel" runat="server" Text='<%# Eval("SupplierID") %>'></asp:Label><br /> CategoryID: <asp:Label ID="CategoryIDLabel" runat="server" Text='<%# Eval("CategoryID") %>'></asp:Label><br /> QuantityPerUnit: <asp:Label ID="QuantityPerUnitLabel" runat="server" Text='<%# Eval("QuantityPerUnit") %>'></asp:Label><br /> UnitPrice: <asp:Label ID="UnitPriceLabel" runat="server" Text='<%# Eval("UnitPrice") %>'></asp:Label><br /> UnitsInStock: <asp:Label ID="UnitsInStockLabel" runat="server" Text='<%# Eval("UnitsInStock") %>'></asp:Label><br /> UnitsOnOrder: <asp:Label ID="UnitsOnOrderLabel" runat="server" Text='<%# Eval("UnitsOnOrder") %>'></asp:Label><br /> ReorderLevel: <asp:Label ID="ReorderLevelLabel" runat="server" Text='<%# Eval("ReorderLevel") %>'></asp:Label><br /> Discontinued: <asp:Label ID="DiscontinuedLabel" runat="server" Text='<%# Eval("Discontinued") %>'></asp:Label><br /> CategoryName: <asp:Label ID="CategoryNameLabel" runat="server" Text='<%# Eval("CategoryName") %>'></asp:Label><br /> <br /> <asp:Button ID="del" runat="server" CommandName="dele" Text="Button" /> </ItemTemplate> </asp:DataList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT * FROM [Alphabetical list of products]"></asp:SqlDataSource> </form>
后台
protected void Page_Load(object sender, EventArgs e) { } protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "dele") { Button dele = (Button)e.Item.FindControl("del"); dele.Text=e.CommandArgument.ToString(); Response.Write("<mce:script language = javascript><!-- alert('别删了,试试就可以了!'); // --></mce:script>"); } } protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { Button dele = (Button)e.Item.FindControl("del"); dele.OnClientClick = "javascript:return confirm('您确定要删除该项么?')"; dele.CommandArgument = DataBinder.Eval(e.Item.DataItem, "ProductID").ToString(); }
相关文章推荐
- 使用Repeater中的OnItemCommand,OnItemDataBound
- ASP.NET 2.0中DataList控件与GridView控件的使用实例
- 使用DataList控件进行数据访问的综合实例
- c#经典编程实例(五使用窗体控件)
- 关于DataList使用DropDownList的分页实现 技巧实例源码
- ASP.NET控件Button (e.CommandArgument的使用方法)
- Repeater数据控件的两个重要事件ItemDataBound 和 ItemCommand
- hadoop中使用MapReduce编程实例(转---超级实用)
- ASP.net datalist,gridview 编辑模板里面控件的使用;
- MFC Combox SetItemData与GetItemData使用实例
- 实例解析C#设计模式编程中简单工厂模式的使用
- Listview控件使用SimpleAdapter适配器实现屏幕下滑增加一个item选项以及用到的方法总结
- 用python3+PyQt5改写Python Qt GUI快速编程的第6章实例主窗口 信号及槽如何使用
- DataList的问题 - ItemCommand事件不响应
- 如何使用 DataBinder.Eval(Container.DataItem,"num","{0:p}") 对DataList 进行数据绑定
- DataList控件使用详解
- 使用PagedDataSource类实现DataList和Repeater控件的分页显示[转]
- 一起去看小学期之Android编程 - 列表控件使用
- python网络编程之TCP通信实例和socketserver框架使用例子
- 使用dataitem从DetailsView的databound事件中读取绑定的数据