ARTICLE

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

Posted by Shinuraj Articles | ASP.NET Programming February 18, 2011
Here is one sample code that explains how to use the DynamicField class inside a Gridview
Reader Level:

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

Login to add your contents and source code to this article
post comment
     
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter