数据源的类型无效。它必须是 IListSource、
public tb_NewsType GetModel(int N_TypeId)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 N_TypeId,N_TypeName,N_FTypeId from tb_NewsType ");
strSql.Append(" where N_TypeId=@N_TypeId ");
SqlParameter[] parameters = {
new SqlParameter("@N_TypeId", SqlDbType.Int,4)};
parameters[0].Value = N_TypeId;
tb_NewsType model = new tb_NewsType();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["N_TypeId"].ToString() != "")
{
model.N_TypeId = int.Parse(ds.Tables[0].Rows[0]["N_TypeId"].ToString());
}
model.N_TypeName = ds.Tables[0].Rows[0]["N_TypeName"].ToString();
if (ds.Tables[0].Rows[0]["N_FTypeId"].ToString() != "")
{
model.N_FTypeId = int.Parse(ds.Tables[0].Rows[0]["N_FTypeId"].ToString());
}
return model;
}
else
{
return null;
}
}
this.ddlNewsType.DataSource = ntb.GetModel(model.N_TypeId);
this.ddlNewsType.DataTextField = "N_TypeName";
this.ddlNewsType.DataValueField = "N_TypeId";
this.ddlNewsType.DataBind();
...全文
相关推荐
Repeater绑定dictionary数据源代码及报错解决
然而,如果遇到“repeater 使用的是无效数据源。有效数据源必须实现IListSource或IEnumerable?”这样的错误,这通常是因为数据源不支持直接绑定。
C#数据绑定控件中的DataSource属性浅谈
- 数组:固定大小的集合,可以是基本类型或自定义类型的实例。 - 实现IListSource接口的组件,如DataSet和DataTable,它们能提供多个数据表。
datagridview详解
它支持对数据源的绑定、编辑和显示,可以显示和编辑来自多种不同类型的数据源的表格数据。3.
C#如何利用反射将枚举绑定到下拉框详解
然而,直接将枚举绑定到ComboBox控件上并不直接可行,因为枚举类型并不实现IEnumerable接口或IListSource接口,这是ComboBox支持的数据源类型。
.NET程序员基础问题和答案
、DataSet、DataViewManager,以及任何实现了 IListSource 或 IList 接口的对象。


