Creating a DetailsView for a SubSonic data object

The DetailsView control helps accelerate web application development. For a recent ASP.NET project, we used it in conjunction with SubSonic to create a rapid prototype.

The data objects generated by SubSonic make it easy to create and configure a DetailsView control.

First, create the necessary controller if needed. Here's the partial class I created for the Share table:

using System.ComponentModel;

namespace CustomerProject.Data

{

    public partial class ShareController

    {

        [DataObjectMethod(DataObjectMethodType.Select, false)]

        public ShareCollection FetchByProjectID(object ProjectID)

        {

            return FetchByQuery(

                Share.CreateQuery()

                    .AddWhere("ProjectID", ProjectID));

        }

    }

}

Start by dragging a DetailsView onto the design surface

image

Click on the arrow to the right of the DetailsView. Under Choose Data Source, select <New data source…>

clip_image003

Select Object, and provide a name.

clip_image005

Select the appropriate SubSonic-generated controller.

image

Choose the Select method.

clip_image009

Define parameters for the Select method

clip_image011

Now you've got a DetailsView on the page.

image

Use Source view to delete unneeded fields.

image

Finally, change the default view to Edit, and remove the height and width parameters.

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="sharesDataSource" DefaultMode=Edit>


Feedback

No comments posted yet.


Post a comment





 

Please add 4 and 4 and type the answer here: