Author: Internet Prodigal Box (formerly known as littlehb) http://blog.9cbs.net/littlehb/ method: using template column
We add a temple column in the DataGrid that binds the data, places a button
Method 2: Use the button column
We add a delete button column Now use the button columns, you cannot set the ID attribute on the button column, and FindControl is looking for controls through the ID (of course we can also use the previous code. E.Item.cells [4]. The code of .controls [0] is replaced.). Add a serial number Good binding a DataGridswitch (e.Item.ItemType) {case (ListItemType.Item): case (ListItemType.AlternatingItem): {DataGridItem row = (DataGridItem) e.Item; TableCell cell = new TableCell (); cell.Controls. Add ((E.Item.itemindex 1) .tostring ())); Row.cells.Addat (0, Cell); Break;} Case (ListItemType.Header): {DataGridItem Row = (DataGridItem) e .Item; Tablecell Cell = new Tablecell (); cell.controls.add (new literalcontrol ("serial number)); row.cells.addat (0, cell); break;}} Here we used E.Item.ItemIndex Get the index of the DataGridItem object from the Items collection from the DataGrid control. Create two tips Bind a DataGrid, set the allowable paging, set the page navigation as a top and bottom, will force the top page navigation to the title line. Here I want to talk about the top Pager of the DataGrid, used to place paging navigation , Then the head header, followed by Item and AlternatingItem projects and alternating projects (of course, there are SelectedItem selection and EditItem Edit item, etc.), then the Footer foot, the bottom there is also a Pager. Because the PAGER line is automatically generated, this is not captured in the ItemDatabase event, here I use it. Itemcreated event, add code Switch (E.Item TimemType) {copy (ListItemType.Pager): {if (first) {dataGridItem ROW = (dataGridItem) E.Item; row.cells.clear (); TableCell Cell0 = New Tablecell (); cell0.controls.add (New LiteralControl ("ID"))); TableCell Cell1 = New TableCell (); cell1.columnspan = 2; cell1.controls.add (New LitralControl ("fullname")); row. Cells.add (Cell0); row.cells.add (Cell1);} first =! First; break;}} The first of this is used to determine the above PAGER or the following Pager.