开发者

DotNetNuke: ObjectDataSource for GridView not being found

As a follow-up to a previous question about GridView and DotNetNuke, I'm having a little more trouble getting things to act correctly. Right now I have a simple GridView in my ascx file and I bind the data to the GridView in my .cs file like so:

DiscoveryController objDiscoverys = new DiscoveryController();
List<DiscoveryInfo> lstDiscoveries = objDiscoverys.GetDiscoverys(ModuleId);

grdDiscoverys.DataSource = lstDiscoveries;
grdDiscoverys.DataBind();

This works. However, I have seen an alternate method in a tutorial which instead defines an <asp:ObjectDataSource> in the controller, and this seems to allow the Designer to do more intelligent things, such as add functioning Delete buttons through a checkbox. Later on in the tutorial, I see inline editing being done as well, which is functionality I desire.

So I decided to give it a shot. To wit:

<asp:ObjectDataSource ID="objDataSource" runat="server" TypeName="MyCompany.Modules.Discovery.DiscoveryController" />

As my dll file in the bin folder is named MyCompany.Modules.Discovery (which matches the assembly name and default namespace I have set up in my C# project), this makes perfect sense. As the tutorial says, I then used the Designer to attempt to bind the Data Source to the GridView.

However, I get an error message that it can't be loaded. The namespace names and class name match up, and I can clearly bind it from the codebehind, so what gives?

EDIT: A follow up. After some experimentation, I have discovered that while the Designer cannot see my module, the .ascx template itself can. Putting this in my .ascx file seems to work...for the most part:

<asp:ObjectDataSource ID="objDataSource" runat="server" TypeName="MyCompany.Modules.Discovery.DiscoveryController" SelectMethod="GetDiscoverys" UpdateMethod="UpdateDiscovery" DeleteMethod="DeleteDiscovery">
    <SelectParameters>
        <asp:QueryStringParameter Name="ModuleId" QueryStringFie开发者_JAVA技巧ld="mid" />
    </SelectParameters>
    <UpdateParameters>
        <asp:QueryStringParameter Name="ModuleId" QueryStringField="mid" />
    </UpdateParameters>
    <DeleteParameters>
        <asp:QueryStringParameter Name="ModuleId" QueryStringField="mid" />
    </DeleteParameters>
</asp:ObjectDataSource>
<asp:GridView ID="grdDiscoverys" runat="server" DataSourceID="objDataSource" EnableModelValidation="True" AutoGenerateColumns="false" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" DataKeyNames="ItemId">
    <Columns>
        <asp:BoundField DataField="ItemId" HeaderText="#" ReadOnly="true" />
        <asp:BoundField DataField="Title" HeaderText="Title" />
        <asp:BoundField DataField="Image" HeaderText="Image URL" />
        <asp:BoundField DataField="Link" HeaderText="Link" />
    </Columns>
</asp:GridView>

Fantastic...it looks like I've mirrored most of the functionality of what the Designer would have added...except for one teensy little thing. The automatic update doesn't update.

More specifically, I get this message when I try to update a field:

ObjectDataSource 'objDataSource' could not find a non-generic method 'UpdateDiscovery' that has parameters: ModuleId, Title, Image, Link, ItemId.

Of course it doesn't work! The method signature goes like this:

public void UpdateDiscovery(DiscoveryInfo objDiscovery)

At this point, I'm so close to getting something working that I can taste it, and DAL-be-damned I'm about to change the function so it takes those five exact params instead of a data object. However, the tutorial that I referenced above seemed to somehow convince the automatic update to pass a data object, so I'm kind of curious to know how it got away with it.


Change your object data source declaration to match your update method:

public void UpdateDiscovery(DiscoveryInfo objDiscovery)

Use single parameter in update parameter declaration:

<UpdateParameters>
        <asp:Parameter Name="objDiscovery" />
    </UpdateParameters>
use object data source's updating event to create an object from the existing control set and assign it to parameter's default value.

Good luck

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜