前台代码 <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(); }