【问题标题】:ObjectDataSource Convert issue - ExceptionObjectDataSource 转换问题 - 异常
【发布时间】:2012-05-30 10:59:32
【问题描述】:

我有一个 Gridview 控件,我想根据页面上的一些控件动态绑定它。除了我试图动态设置 Select 方法以及传递参数的以下代码之外,我已经让一切正常工作。我遇到了一个异常,我尝试了多种创建参数的方法。附上代码:

string filterValue = FilterValue.Value; //FilterValue.Value is a HiddenField (Value is definitely populated)

MyObjDataSource.SelectParameters.Add("policynumber",TypeCode.String, filterValue);    
MyObjDataSource.SelectMethod = "GetPolicybyPolicyNumber";    
MyObjDataSource.Select();

我的选择方法如下所示:

public IQueryable GetPolicybyPolicyNumber(Parameter policynumber, string sortExpr, int maximumRows, int startRowIndex)
    {
       //Debugging does not even reach here. I'm just returning null for demo purposes
       return null;
    }

我不断得到的例外是:

System.InvalidOperationException:无法将参数“policynumber”的值从“System.String”转换为“System.Web.UI.WebControls.Parameter”
在 System.Web.UI.WebControls.ObjectDataSourceView.ConvertType(Object value, Type type, String paramName) ....

我也试过这个,它给出了同样的例外:

    Parameter param = new Parameter();
    param.Type = TypeCode.String;
    param.DefaultValue = FilterValue.Value;
    MyObjDataSource.SelectParameters.Add(param);

有什么建议吗? 发送

【问题讨论】:

    标签: c# asp.net data-binding objectdatasource


    【解决方案1】:

    将第一个参数数据类型更改为字符串,如下所示

    public IQueryable GetPolicybyPolicyNumber(string policynumber, string sortExpr, int maximumRows, int startRowIndex){...}

    【讨论】:

      猜你喜欢
      • 2013-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多