我如何告诉如果ObjectDataSource控件OnSelected事件呼吁selectmethod或selectcountmethod? [英] How do I tell if the ObjectDataSource OnSelected event was called for the selectmethod or selectcountmethod?
本文介绍了我如何告诉如果ObjectDataSource控件OnSelected事件呼吁selectmethod或selectcountmethod?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个对象的数据源,看起来像这样:
I have an object datasource that looks like this:
<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事件:
And a onselected event like this:
protected void obdsList_Selected(object sender, ObjectDataSourceStatusEventArgs e) {
}
但是,事件方法被调用了两次。一旦我返回列表中,并用返回的Int32计数一次。如果我想投 e.ReturnValue
来返回列表如何计数和选择方法区分?我可以做一个 e.ReturnValue.GetType()的ToString()
但是,似乎是一个黑客攻击。
However, the event method is being called twice.. once with my returned list, and once with the returned Int32 count. If I want to cast e.ReturnValue
to the return List how do I differentiate between the count and select methods? I can do a e.ReturnValue.GetType().ToString()
but that seems like a 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
}
}
}
这篇关于我如何告诉如果ObjectDataSource控件OnSelected事件呼吁selectmethod或selectcountmethod?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文