CYQ. Data lightweight Data access layer (7) Custom Data Tables bind Common Data Controls (I)

Source: Internet
Author: User

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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.