C# 通过ObjectDataSource将ListItemCollection传递给自定义适配器时出错
我有一个C# 通过ObjectDataSource将ListItemCollection传递给自定义适配器时出错,c#,asp.net,serialization,webforms,objectdatasource,C#,Asp.net,Serialization,Webforms,Objectdatasource,我有一个ObjectDataSource声明如下: <asp:ObjectDataSource ID="PaymentsDataSource" runat="server" DataObjectTypeName="Payment" TypeName="PaymentAdapter" SelectMethod="Get
ObjectDataSource
声明如下:
<asp:ObjectDataSource ID="PaymentsDataSource"
runat="server"
DataObjectTypeName="Payment"
TypeName="PaymentAdapter"
SelectMethod="GetPayments">
<SelectParameters>
<asp:ControlParameter ControlID="StartDate"
PropertyName="Text"
Name="startDate"
Type="DateTime" />
<asp:ControlParameter ControlID="EndDate"
PropertyName="Text"
Name="endDate"
Type="DateTime" />
<asp:ControlParameter ControlID="LocationCodes"
PropertyName="Items"
Name="selectedLocationCodes"
Type="Object" />
</SelectParameters>
</asp:ObjectDataSource>
<select id="LocationCodes"
disabled="disabled"
runat="server"
class="chzn-container"
multiple=""
data-placeholder="Choose a Location Code(s)"
style="width: 100%;"
data-class="span10">
</select>
[DataObjectMethod(DataObjectMethodType.Select, true)]
public List<Payment> GetPayments(
DateTime startDate,
DateTime endDate,
object selectedLocationCodes)
{
}
适配器上的服务器端Select
方法定义如下:
<asp:ObjectDataSource ID="PaymentsDataSource"
runat="server"
DataObjectTypeName="Payment"
TypeName="PaymentAdapter"
SelectMethod="GetPayments">
<SelectParameters>
<asp:ControlParameter ControlID="StartDate"
PropertyName="Text"
Name="startDate"
Type="DateTime" />
<asp:ControlParameter ControlID="EndDate"
PropertyName="Text"
Name="endDate"
Type="DateTime" />
<asp:ControlParameter ControlID="LocationCodes"
PropertyName="Items"
Name="selectedLocationCodes"
Type="Object" />
</SelectParameters>
</asp:ObjectDataSource>
<select id="LocationCodes"
disabled="disabled"
runat="server"
class="chzn-container"
multiple=""
data-placeholder="Choose a Location Code(s)"
style="width: 100%;"
data-class="span10">
</select>
[DataObjectMethod(DataObjectMethodType.Select, true)]
public List<Payment> GetPayments(
DateTime startDate,
DateTime endDate,
object selectedLocationCodes)
{
}
好的,我解决这个问题的方法是通过在
ObjectDataSource
元素上关闭ViewState
来添加这个ViewStateMode=“Disabled”
问题是无法序列化对象。如果你要改变
“object selectedLocationCodes”指向某种预定义类,则应该没有问题。
为了序列化对象,基本上需要将其分解为XML,这意味着它需要知道每个字段的数据类型。对象的描述不够具体,因为它可以是任何对象