ASP. NET futures-Dynamic Data Control: In-depth

Source: Internet
Author: User

Official station: http://quickstarts.asp.net/Futures/default.aspx

This article gives a more in-depth introduction to the use of dynamic data controls (including custom methods), including the following parts:

  1. Locate Database
  2. Ing to tables or views in the database
  3. Other Dynamic Data Controls
  4. Use extended mode to customize display styles
  5. Select columns to display
  6. Create custom Columns
  7. Customize the display style of a row
  8. Custom Data sources

 

Locate Database

The Dynamic Data Control selects a database in the following order:

  1. If Web. config contains the <dynamicdatacontrols> definition and <dynamicdatacontrols> declares the database connection string, the dynamic data control uses the database:

    <dynamicDataControls showAllTables="true"
            dataLayerType="Microsoft.Web.DynamicDataControls.SqlDataLayer"
            connectionString="TASKSConnectionString" > 
        <nameMap>
        </nameMap>
    </dynamicDataControls>

  2. If the web. config does not contain the <dynamicdatacontrols> section, or <dynamicdatacontrols> does not declare a database connection string, and the Web. config exactly contains one and only one database connection string, so the Dynamic Data Control will use this database. If Web. config contains multiple database connection strings, you must declare the database connection string in <dynamicdatacontrols>.
  3. If no database connection string exists in Web. config, but app_data contains a database file, the dynamic data control uses the database. If app_data contains multiple database files, the database connection string must be declared.

 

Ing to tables or views in the database

For example, if there is a table or view named MERs in the database:

The Dynamic Data Control defined in mers MERs. aspx automatically maintains data in the customers table.

If you need to use multiple pages to maintain the MERs table, you can name it like this. Note: List. aspx and details. aspx have special meanings. Used to display data in a list or in detail:

~/Customers/list.aspx
~/Customers/details.aspx
~/Customers/anotherCustomView.aspx

However, we can also overwrite this default setting. For example, <dynamicdatacontrols>:

<dynamicDataControls listView="MyList" detailsView="MyDetails">
    <nameMap>
        <add table="customers" pathPrefix="~/MyCustFolder" />
    </nameMap>
</dynamicDataControls>

Map the MERs table to the mycustfolder folder instead of the default customers folder. In addition, the names of list. aspx and details. aspx should also be changed to mylist. aspx and mydetails. aspx.

 

Other Dynamic Data Controls

Currently, ASP. NET Futures provides the following dynamic data controls:

  1. Dynamicautodata: Display all the following controls on a single page. ASP. NET futures-Dynamic Data Control: Getting Started This article uses this control as an example program.
  2. Dynamiclist: Display the table as a gridview.
  3. DynamicdetailsDisplay the table as detailsview, that is, only one row of data in the table is displayed.
  4. Dynamicfilter: Allows users to filter data.
  5. DynamicinsertAllows you to insert data.
  6. Dynamicnavigator: Allows you to navigate between all current dynamic data control pages.
  7. Dynamicrsslink: Provides data in RSS mode.

 

Use extended mode to customize display styles

To control the display style of data, simply use the extended mode of the Dynamic Data Control:

<asp:DropDownList runat="server" ID="ddl"BackColor="Yellow" Font-Italic="true" /><asp:DynamicFilter runat="server" ColumnName="Category" ControlID="ddl" />

In this way, you can first define the data display style, and then use the Dynamic Data Control to "fill in" the data.

 

Select columns to display

Override the getcolumns () method to control which columns in the table are displayed by the dynamic data control, for example:

public override IEnumerable GetColumns()
{
    return new object[] { "Description", "Complete" };
}

 

Create custom Columns

To create a custom column, you only need to override the getcolumns () method:

public override IEnumerable GetColumns()
{
    return new object[] { 
        "Category",
        new DynamicDataColumn(
            delegate { return EvalS("ShipName") + " (" + 
                EvalS("ShipAddress") + ")"; })
    };
}

However, the title of the newly added column is "M m column" by default ". To specify a meaningful name, use the following code:

public override IEnumerable GetColumns()
{
    return new object[] { 
        "Category",
        new DynamicDataColumn(
            "Description (Complete)",
            delegate { return EvalS("ShipName") + " (" + 
                EvalS("ShipAddress") + ")"; }
        )
    };
}

The above code can also use a Custom column title.

 

Customize the display style of a row

To customize the display style of a row, you only need to override the initrow () method:

public override void InitRow(GridViewRow row)
{
    if (EvalS("ShipName").IndexOf("Buy") > -1)
    {
        row.BackColor = Color.Yellow;;
    }
}

 

Custom Data sources

Override the initdatasource () method to complete the custom data source function:

public override void InitDataSource(IDataSource dataSource)
{
    dataSource.FilterExpression = ...;
}

 

Related Article

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.