DynamicField class used by GridView to display data fields that use .NET Dynamic Data features.


Here is one sample code that explains how to use the DynamicField class inside a Gridview

Follow the steps to add dynamic behavior to a GridView

  1. In Visual Studio 2010 open the Web site.
  2. Add one EntityDataSource control or the LinqDataSource control.
  3. Add a GridView control and DynamicDataManager control to the page.
  4. Set the ControlID property of the DataControlReference element in the DynamicDataManager control to the ID of the GridView control.
  5. Set the DataSourceID property of the GridView control to the ID of the EntityDataSource control or the LinqDataSource control.
  6. For each column in the GridView control add a DynamicField control as shown in the ASPX code below

And set the DataField property of the DynamicField control to the name of the data column or row that you want to bind to.

ASPX:

<asp:GridView     ID="GridView1"

runat="server" DataSourceID="GridDataSource"

EnablePersistedSelection="True" AutoGenerateColumns="False" GridLines="None" AllowPaging="True" AllowSorting="True"  >

    <Columns>
     <asp:DynamicField DataField="ProductID" HeaderText="Product ID" />
     <asp:DynamicField DataField="ProductName" HeaderText="Product Name" />
     <asp:DynamicField DataField="Description" HeaderText="Description" />
     <asp:DynamicField DataField="ModifiedDate" HeaderText="Modified Date" />
    </Columns>

    <PagerTemplate>
        <asp:GridViewPager runat="server" />
    </PagerTemplate>
    <EmptyDataTemplate>
        There are currently no items in this table.
    </EmptyDataTemplate>   
</asp:GridView>

Shinu

Up Next
    Ebook Download
    View all
    Learn
    View all