问题
I'm working on a DotNetNuke module in C#, and in order to cut down on the amount of complexity I have elected to try and keep the configuration of the module in one page (other than the standard Settings module). I now wonder how wise of an idea that is.
My module is a simple image gallery, with one or many images. Each image has a title, an image source (url) and a destination (another url). Therefore, I figured that for my admin interface, I could have a simple 'grid' of data where you can edit all of the existing entries or add a new one, all on the same page, sort of like this:
Title Image URL Anchor HREF [A Picture! ] [http://www.example.com/image.jpg ] [http://www.example.com] [Another Picture!] [http://www.example.com/image2.jpg] [http://www.example.net] [ ] [ ] [ ]
Looking through WebControls, I found the GridView, which at first blush seemed like the sort of thing I was looking for. However, taking a closer gander at it, I found that it needed to be bound directly to a data source, while it seems like the DotNetNuke standard of doing things in the Data Access Layer is to create a collection of data objects like so:
// EditDiscovery.ascx.cs
DiscoveryController objDiscoverys = new DiscoveryController();
List<DiscoveryInfo> lstDiscoveries = objDiscoverys.GetDiscoverys(ModuleId);
// DiscoveryController.cs
public List<DiscoveryInfo> GetDiscoverys(int ModuleId) {
return CBO.FillCollection<DiscoveryInfo>(DataProvider.Instance().GetDiscoverys(ModuleId));
}
Is there something I'm missing with the GridView, or should I be changing the GetDiscoverys function to return a DataSet as opposed to a List of DiscoveryInfo objects? Or is there a better approach that does things that align better with DotNetNuke's DAL?
回答1:
You should be able to set the list of DiscoveryInfo
objects to the grid.
MyGrid.DataSource = lstDiscoveries;
MyGrid.DataBind();
来源:https://stackoverflow.com/questions/4795173/dotnetnuke-gridview-incompatible-with-data-access-layer