0

So my formview has about 30 fields. Is it possible I can send all these parameters as an object to my update method, rather than sending each one of them separately as a parameter?

Thanks --

4

1 回答 1

0

I think you can make use of the ObjectDataSource. When you define your ObjectDataSource, you specify the functions you want it to use (e.g. UpdateMethod attribute) and the type of object that should be passed to that function (e.g. DataObjectTypeName attribute).

Then when your form is submitted, it will automatically call the UpdateMethod you have specified, passing it the object filled with the values from your FormView. In order to do this, you have to Bind your FormView controls to the object properties.

Here are some code samples...

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
    SelectMethod="GetItem" 
    InsertMethod="InsertItem" 
    UpdateMethod="UpdateItem" 
    TypeName="ClassName_OfMyObjectContainingMethodsSpecifiedAbove"
    DataObjectTypeName="ClassName_OfMyDataObject" >

<asp:FormView ID="FormView1" runat="server" 
    DataSourceID="ObjectDataSource1" DataKeyNames="PropertyName_OfMyKeyField">

    <EditItemTemplate>

        <asp:TextBox ID="TextBox_Description" runat="server" 
            MaxLength="50" Columns="30" 
            Text='<%# Bind("Description") %>' />

    </EditItemTemplate>

</asp:FormView>
于 2013-05-07T14:55:55.293 回答