Several tips for DataGrid

xiaoxiao2021-03-05  20

Give a prompt method 1: Use the template to add a temper column to the DataGrid binding data, place a button in the column

Then we add the following code Switch (ListItemType.ItemType) {CASE (ListItemType.ArternatingItem): {Button BTN = (Button) E.Item.FindControl ("btndelete") btn.attributes.add ("onclick", "Return Window.confirm ('fs')"); Break;}} DataGrid will trigger this event when binding data, and each row trigures once. We can pass E .Item gets a line, and get a line type by E.Item.itemType. Method 2: Use the button column to add a DataGrid that is bound to add a delete button column

Then we add the following code Switch (E.Item.itemType) {copy (ListItemType.AitemType): {linkbutton btn = (linkbutton btnatingItem): {linkbutton btn = (linkbutton btn = (limited) E.Item.cells [4] .controls [0]; btn.attributes.add ("onclick", "Return Window.confirm ('fs')"); Break;}} You can see the method we get the control reference here is different, use E.Itemm .Cells [4] .controls [0], without using E.Item.FindControl ("btndelete"), because we now use the button column, you cannot set the ID attribute for the button column, and FindControl is coming through the ID Find controls (of course, we can also replace the previous code with the code of E.Item.cells [4] .Controls [0].) Add a serial number list 1 a DataGrid Switch (E.Item.ItemType) {casse (ListItemType.Item): case (ListItemType.AlternatingItem): {DataGridItem row = (DataGridItem) e.Item; TableCell cell = new TableCell (); cell.Controls.Add (new LiteralControl ((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 ("serial number)); row.cells.addat (0, cell); Break;}} Here we use E.Item.itemindex to get the index of the DataGridItem object from the DataGrid control. Generate the title line of the two lines to bind a good one DataGrid, set the allowable paging, set page navigation as a top and down type, 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 the paging navigation, then Header header, followed by Item and AlternatingItem projects and alternating projects (of course, there are SELECTEDITEM selection items, etc.), then the Footer feet, the bottom there is also a Pager. Because the Pager line is automatically generated, so This line cannot be captured in the ItemDatabase event. Here I use Itemcreated events, add code as the following Switch (E.Item.ItemType) {copy (ListItemType.Pager): {if (first) {dataGridItem ROW = (DataGridItem) E.ITEM Row.cells.clear (); TableCell Cell0 = new TableCell (); cell0.controls.add (New LitralControl ("ID")); TableCell Cell1 = New Tablecell (); cell1.columnspan = 2; cell1.controls. Add ("fullname")); row.cells.add (cell0); row.cells.add (cell1);} first =! First; Break;

转载请注明原文地址:https://www.9cbs.com/read-38193.html

New Post(0)