After MDataTable is implemented in the previous section, we add a NewRow () method to MDataTable to construct a new row for this table.
As follows:
Code
Public MDataRow NewRow ()
{
MDataRow MCM = new MDataRow ();
MCM. TableName = _ TableName;
MDataCellStruct mdcStruct = null;
For (int I = 0; I <this. Columns. Count; I ++)
{
MdcStruct = this. Columns [I];
MCM. Add (new MDataCell (ref mdcStruct ));
}
Return MCM;
}
OK. Next, create a Demo web project, drag a GridView control in Default. aspx, and write the following code in Page_Load:
Code
MDataTable table = new MDataTable ("myTableName ");
Table. Columns. Add ("A", SqlDbType. NVarChar );
Table. Columns. Add ("B", SqlDbType. NVarChar );
MDataRow MCM = table. NewRow ();
MCM [0]. Value = "helloA ";
MCM [1]. Value = "111111 ";
Table. Add (MCM );
GridView1.DataSource = table;
GridView1.DataBind ();
This is the case when you try to knock the MCM ["A"]. If you do not support string cable, you have to knock the MCM [0]. Here, we can add A string index to MDataRow, as shown below:
Code
Public MDataCell this [string Key]
{
Get
{
MDataCell dataCell = null;
For (int I = 0; I <base. Count; I ++)
{
If (base [I]. ColumnName = Key)
{
DataCell = base [I];
Break;
}
}
Return dataCell;
}
}
OK. In this way, two column headers are added and a row of data is added. The result is as follows:
TableName |
ConnectionString |
Capacity |
Count |
MyTableName |
|
4 |
2 |
Dizzy, data is not what we want at all ....
The columns shown above are all Table attributes, and ConnectionString is the attributes of Table rows.
Scared, just mix it in one piece ....
So we started to look for the binding method...