Realize the display of the main slave table with nested DataGrid

zhaozj2021-02-16  46

Realize the display of the main slave table with nested DataGrid

After half a year of ASP.NET learning and development practice, as the Society's things are increasing, it is also constantly increasing, despite this, during this time still more or less accumulated Some personal development experiences, most important is how to learn how to use knowledge and techniques that have been known to complete their own goals.

How to implement the display of the master-slave table is a problem that I have encountered in my development, which also involves the problem of using check box controls and custom DataGrid in DataGrid. The following three questions will be solved one by one.

First, use the checkbox control in DataGrid

There are several ways to solve this problem, I chose a way to apply both the checkbox control and the radio box control. The specific implementation is as follows:

Create a ButtonColumn for DataGrid, or create a template column, put a Label control in the template column (Note: The choice of these controls is not unique). Then generate the HTML tag of the DataGrid (radio box control) and set the corresponding property in the DataGrid table during the DataGrid's ItemDatabase event. The statement that generates the HTML tag of the check box control is as follows:

1 if E.Item.itemType = ListiteMType.AlternatingItem OR E.Item.itemType = ListItemType.Item Then

2 DIM R as LinkButton

3 r = E.Item.cells (2) .controls (0)

4 r.Text = ""

Else

R.Text = "

2. Clear the default control in Header;

E.Item.Controls.clear ()

3. Create a new unit control,

DIM CELL0 AS New TableCell

Cell0.controls.add (New LiteralControl ("Header1"))

E.Item.controls.add (Cell0)

And can be set by setting attributes such as cell style, background, width, height, location, etc. by the following statement:

Cell0.mergeStyle (Dgallrights.Headerstyle)

Cell0.backcolor = color.fromname ("# 8faae7")

Cell0.Width = Unit.Percentage (10)

Cell0.height = unit.pixel (intHEight)

Cell0.horizontalalign = horizontalalign.ceter

4. Repeat step 3 and create all other three cell controls.

So far, Header is created, but due to the change of Header, the column of ITEM has changed, and the 2 columns become 4 columns, so we need to make Item cell merge operation, the specific statement is as follows:

'Set the columnspan merging unit properties of the second column of Item

If E.Item.ItemType = ListItemType.alternatingItem or E.Item.itemType = ListItemType.Item Then

Dim Cell As Tablecell

Cell = E.Item.cells (1)

Cell.columnspan = 3

END IF

Third, DataGrid nested display master-slave table

After the solvement of the above two questions, especially the solvement of the second question, it can be said that the implementation of this problem is very easy.

First, create a template column for the main DataGrid, place from the DataGrid control from the DataGrid control, set to false from the DataGrid control from the DataGrid control, and the use of the check box control is implemented from the DataGrid control, and the form of the main DataGrid is based on The second problem described above is customized. So the main DataGrid and the data source from the DataGrid control can also be different. Then according to your own needs, the pattern is set, the following is the result of the final result:

Of course, in addition to this method, there must be other methods to be realized, the key is to try more, and there will be some unexpected gains during the continuous trial.

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

New Post(0)