9CBS - Document Center - .NET title to DataGrid Add to determine the deleted function cuike519 (original) keyword DataGrid
Add determination of delete function for DataGrid DataGrid's function. I want to know, I encountered the following problems in actual applications, and customer requirements do a prompt before deleting. Category is similar to Windows. First we all know that DataGrid supports deleting features, we can add delete columns to DataGrid to implement, below I want to use the template column to implement the removal button with prompt. We use Northwind's sample database as an example database to operate Categories table. DataGrid's HTML page is as follows: ask: button> itemtemplate> asp: templateColumn> columns> ask: DataGrid> We only add a template column, and other columns are automatically generated when running. It can be seen that this template column is very like deleting columns but is not deleting columns, we add a common button = "delete" attribute to an ordinary button. This is used to respond to the itemCommand event of DataGrid! This is like this in the delete column! The next is the background code, the code is as follows: private Dataset DS = New DataSet (); private void page_load (Object sender, system.eventargs e) {// Place the user code here to initialize the page if (! This. . IsPostBack) {string strConnection = ConfigurationSettings.AppSettings [ "sa"] ToString (); SqlConnection myConnection = new SqlConnection (strConnection); SqlDataAdapter myAdapter = new SqlDataAdapter ( "SELECT CategoryID, CategoryName, Description FROM Categories", myConnection); myAdapter. Fill (DS); this.grdtest.datasource = ds.tables [0] .defaultview; this.grdtest.dataKeyfield = "categoryID"; this.grdtest.database ();}} Next we give each template column The button adds a client's onclick event. I want everyone to know the Attributes property! You can output the properties of the client control to the client, such as: length, color, and so on. But usually we use it to add client events.