UpdateParameters,InsertParameters参数的顺序一定要跟方法的参数顺序一样才可以,否则会抛出异常,说没有这个异常方法.
如:ObjectDataSource的UpdateMethod的方法为Update(string a,string b,int c),那么你UpdateParameters的参数应该这样写
<UpdateParameters>
<asp:Parameter Name="a" Type="String" />
<asp:Parameter Name="b" Type="String" />
<asp:Parameter Name="c" Type="Int32" />
</UpdateParameters>
2.
在用ObjectDataSource的时候,我发现数据显示控件里面的参数跟ObjecDataSource的参数是可以不区分大小写的,但在事件中读取参数的时候,参数的名字一定要跟ObjectDataSource设置的参数一摸一样,是区分大小写的.
如下面的代码:
<asp:FormView ID="fv" runat="server" DefaultMode="Insert" DataSourceID="odsFV" OnItemUpdated="fv_ItemUpdated"
OnItemInserting="fv_ItemInserting" OnItemInserted="fv_ItemInserted">
<InsertItemTemplate>
名称:
<asp:TextBox ID="TravelArticleTitleTextBox" runat="server" Text='<%# Bind("travelArticleTitle") %>'>
</asp:TextBox><br />
</InsertItemTemplate>
</asp:FormView>
<asp:ObjectDataSource ID="odsFV" runat="server" InsertMethod="Insert" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetTravelArticleByTravelArticleID" TypeName="Obj.BLL.TravelArticleBLL"
UpdateMethod="Update" OnInserting="odsFV_Inserting">
<SelectParameters>
<asp:QueryStringParameter Name="travelArticleID" QueryStringField="TravelArticleID"
Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:CookieParameter CookieName="UserID" Name="userid" Type="String" />
<asp:Parameter Name="travelArticleTitle" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>
OnItemInserting="fv_ItemInserting" OnItemInserted="fv_ItemInserted">
<InsertItemTemplate>
名称:
<asp:TextBox ID="TravelArticleTitleTextBox" runat="server" Text='<%# Bind("travelArticleTitle") %>'>
</asp:TextBox><br />
</InsertItemTemplate>
</asp:FormView>
<asp:ObjectDataSource ID="odsFV" runat="server" InsertMethod="Insert" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetTravelArticleByTravelArticleID" TypeName="Obj.BLL.TravelArticleBLL"
UpdateMethod="Update" OnInserting="odsFV_Inserting">
<SelectParameters>
<asp:QueryStringParameter Name="travelArticleID" QueryStringField="TravelArticleID"
Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:CookieParameter CookieName="UserID" Name="userid" Type="String" />
<asp:Parameter Name="travelArticleTitle" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>
其中:<asp:TextBox ID="TravelArticleTitleTextBox" runat="server" Text='<%# Bind("travelArticleTitle") %>'>
</asp:TextBox>中Text='<%# Bind("travelArticleTitle") %>'可以为Text='<%# Bind("TravelArticleTitle") %>'
但后台在事件读取参数中,如 protected void fv_ItemInserting(object sender, FormViewInsertEventArgs e){}
我们一定要写 e.Values["travelArticleTitle"] 而不能写