简体   繁体   English

数据源是无效类型。 它必须是 IListSource、IEnumerable 或 IDataSource

[英]Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource

i am trying to fill one details view from the gridview selected index changing event,but i got an error,plz help me我正在尝试从 gridview 选择的索引更改事件中填充一个详细信息视图,但出现错误,请帮助我

public void viewDetailsNew(decimal decDv)
    {
        SubjectInfo infosubject = new SubjectInfo();
        SubjectSp spcubject = new SubjectSp();
        dvSubject.DataSource = spcubject.SubjectViewDetails(decDv);
        dvSubject.DataBind();
        mvSubject.ActiveViewIndex = 1;
    }

public SubjectInfo SubjectViewDetails(decimal decsubjectid)
    {
        SubjectInfo infosubject = new SubjectInfo();
        SqlDataReader sqlreader = null;
        try
        {
            if (sqlcon.State == ConnectionState.Closed)
            {
                sqlcon.Open();
            }
            SqlCommand sqlcmd = new SqlCommand("SubjectView", sqlcon);
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.Parameters.Add("@subjectId", SqlDbType.Decimal).Value = decsubjectid;
            sqlreader = sqlcmd.ExecuteReader();
            while (sqlreader.Read())
            {
                infosubject.subjectId = decimal.Parse(sqlreader["subjectId"].ToString());
                infosubject.subjectName = sqlreader["subjectName"].ToString();
                infosubject.shortName = sqlreader["shortName"].ToString();

            }
        }
        catch
        {
            throw;
        }
        finally
        {
            sqlreader.Close();
            sqlcon.Close();
        }

        return infosubject;
    }

protected void gvViewSubject_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        ViewState["subjectId"] = gvViewSubject.DataKeys[e.NewSelectedIndex]["subjectId"].ToString();
        decimal decDv = decimal.Parse(ViewState["subjectId"].ToString());
        viewDetailsNew(decDv);
    }

You are trying to bind to a single object when you need a collection or IEnumerable当您需要集合或IEnumerable时,您正试图绑定到单个对象

Try this试试这个

 public IEnumerable<SubjectInfo> SubjectViewDetails(decimal decsubjectid)
{
    var list = new List<SubjectInfo>();

    try
    {
        if (sqlcon.State == ConnectionState.Closed)
        {
            sqlcon.Open();
        }
        SqlCommand sqlcmd = new SqlCommand("SubjectView", sqlcon);
        sqlcmd.CommandType = CommandType.StoredProcedure;
        sqlcmd.Parameters.Add("@subjectId", SqlDbType.Decimal).Value = decsubjectid;
        using (var sqlreader = sqlcmd.ExecuteReader())
        {
            while (sqlreader.Read())
            {
                SubjectInfo infosubject = new SubjectInfo();
                infosubject.subjectId = decimal.Parse(sqlreader["subjectId"].ToString());
                infosubject.subjectName = sqlreader["subjectName"].ToString();
                infosubject.shortName = sqlreader["shortName"].ToString();
                list.Add(infosubject);
            }
        }
    }
    catch
    {
        throw;
    }
    finally
    {
        sqlcon.Close();
    }

    return list;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 数据源是无效的类型。 它必须是IListSource,IEnumerable或IDataSource - Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource 数据源是无效类型。它必须是IListSource,IEnumerable或IDataSource - Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource 数据源是无效的类型。 它必须是IListSource,IEnumerable或IDataSource - Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource 数据源是无效的类型。 它必须是IListSource,IEnumerable或IDataSource - Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource 附加信息:数据源是无效的类型。 它必须是IListSource,IEnumerable或IDataSource - Additional information: Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource GridView,它必须是IListSource,IEnumerable或IDataSource - GridView, It must be either an IListSource, IEnumerable, or IDataSource 如何将匿名类型转换为IListSource,IEnumerable或IDataSource - How to convert anonymous type to IListSource, IEnumerable, or IDataSource 附加信息:Complex DataBinding将IList或IListSource接受为数据源 - Additional information: Complex DataBinding accepts as a data source either an IList or an IListSource ([sqlDataReader to comboBox])-复杂数据绑定将IList或IListSource接受为数据源 - ([sqlDataReader to comboBox]) - Complex DataBinding accepts as a data source either an IList or an IListSource 错误:复杂数据绑定接受 IList 或 IListSource 作为数据源 - Error: Complex DataBinding accepts as a data source either an IList or an IListSource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM