學習:AjaxToolKit:ConfirmButton in Repeater)

來源:互聯網
上載者:User
Using a ConfirmButton In a Repeater

Christian Wenz

Overview

The ConfirmButton extender in the AJAX Control Toolkit creates a Yes/No popup when the user clicks on a button (including LinkButton control). Only if Yes is clicked, the button's action is executed, otherwise cancelled. This is also possible in a repeater.

Steps

First of all, a data source is required. This sample uses the AdventureWorks database and the Microsoft SQL Server 2005 Express Edition. The database is an optional part of a Visual Studio installation (including express edition) and is also available as a separate download under http://go.microsoft.com/fwlink/?LinkId=64064. The AdventureWorks database is part of the SQL Server 2005 Samples and Sample Databases (download at http://www.microsoft.com/downloads/details.aspx?FamilyID=e719ecf7-9f46-4312-af89-6ad8702e4e6e&DisplayLang=en). The easiest way to set the database up is to use the Microsoft SQL Server Management Studio Express ( http://www.microsoft.com/downloads/details.aspx?FamilyID=c243a5ae-4bd1-4e3d-94b8-5a0f62bf7796&DisplayLang=en) and attach the AdventureWorks.mdf database file.

For this sample, we assume that the instance of the SQL Server 2005 Express Edition is called SQLEXPRESS and resides on the same machine as the web server; this is also the default setup. If your setup differs, you have to adapt the connection information for the database.

In order to activate the functionality of ASP.NET AJAX and the Control Toolkit, the ScriptManager control must be put anywhere on the page (but within the <form> element):

<asp:ScriptManager ID="asm" runat="server" />

Then, a data source is required. For the sake of simplicity, only the first five entries in AdventureWorks' Vendors table are retrieved. Note that when using the Visual Studio wizard to create the data source, the table name (Vendors) is currently not correctly prefixed with Purchasing. The following markup is the correct one:

<asp:SqlDataSource ID="sds1" runat="server" ConnectionString=" Data Source=(local)\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT TOP 5 [VendorID], [Name] FROM [Purchasing].[Vendor]" />

This data source can then be used within a repeater. As usual, the DataBinder.Eval() method retrieves data from the data source. The ConfirmButtonExtender control must then be placed within the <ItemTemplate> section of the repeater so that it appears for every entry in the data source.

<div> <ul> <asp:Repeater ID="rep1" DataSourceID="sds1" runat="server"> <ItemTemplate> <li> <%#DataBinder.Eval(Container.DataItem, "Name")%> <asp:LinkButton ID="btn1" Text="Remove Item" runat="server" /> <ajaxToolkit:ConfirmButtonExtender ID="cfe1" runat="server" TargetControlID="btn1" ConfirmText="Are you sure?!" /> </li> </ItemTemplate> </asp:Repeater> </ul> </div>

 

The confirm button appears next to each entry from the data source (Click to view full-size image)

 

It come from:http://www.asp.net/ajax/tutorials/using-a-confirmbutton-in-a-repeater-cs

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.