gpt4 book ai didi

c# - 如何判断是为 selectmethod 还是 selectcountmethod 调用了 ObjectDataSource OnSelected 事件?

转载 作者:太空宇宙 更新时间:2023-11-03 20:40:39 24 4
gpt4 key购买 nike

我有一个如下所示的对象数据源:

<asp:ObjectDataSource ID="obdsList" runat="server" 
EnablePaging="True" SelectCountMethod="GetCountByID" SortParameterName="sortExpression"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetByID"
TypeName="Services.Users"
onselected="obdsList_Selected">
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="ID"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

还有一个像这样的 onselected 事件:

protected void obdsList_Selected(object sender, ObjectDataSourceStatusEventArgs e) {
}

但是,事件方法被调用了两次……一次是用我返回的列表,一次是用返回的 Int32 计数。如果我想将 e.ReturnValue 转换为返回列表,我该如何区分 count 和 select 方法?我可以执行 e.ReturnValue.GetType().ToString() 但这似乎是一个 hack。

最佳答案

我在做这个...

protected void obdsList_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.ReturnValue != null)
{
if (e.ReturnValue.GetType() == typeof(int))
{
//e.ReturnValue is the SelectCountMethod value
}
}
}

关于c# - 如何判断是为 selectmethod 还是 selectcountmethod 调用了 ObjectDataSource OnSelected 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2915555/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com