【发布时间】:2013-09-05 20:20:37
【问题描述】:
我已将我的 ListView 绑定到数据库。我已经使用 SqlDataSource 来完成这项工作。我想以编程方式更改数据源,但这就是一切都出错的地方。我尝试通过这样做来获取当前数据源:
SqlDataSource oldSource = lstContacts.DataSource as SqlDataSource;
那我想把SqlDataSource的SelectCommand保存成一个字符串:
string oldSelectCommand = oldSource.SelectCommand;
我这样做是因为我想检查 select 语句是否包含 order by 子句,如果包含,则将其删除并用另一个 order by 子句进行更改:)
但是,我得到了这个:
"System.NullReferenceException: Object reference not set to an instance of an object."
有人吗?请(:
【问题讨论】:
-
在这里提出了类似的问题 - How to access the bound DataSource item in the ASP.NET ListView's DataBound event?,没有解决方案。
标签: asp.net listview sqldatasource selectcommand