将 DataTable 绑定到 DetailsView 控件
我有一个 DetailsView 控件,我想用数据表填充该控件。我在后面的代码中执行此操作。检查数据表创建成功后,代码是:
detailsView.DataSource = dataTable;
detailsView.DataBind();
我运行程序,但详细信息视图没有显示。问题是否是数据表可能有多行,而详细信息视图只有一行?如果这就是问题,有办法解决吗?我在创建数据表时确保它只有一行。我还尝试仅绑定数据表中的一行,但不接受数据表行作为数据源。有什么问题吗?
I have a DetailsView control that I want to populate with a data table. I'm doing this in code behind. After checking that the data table is created successfully, the code is:
detailsView.DataSource = dataTable;
detailsView.DataBind();
I run the program and the detailsView doesn't show.Could the problem be that a data table potentially can have multiple rows and a details view only one? If that's the problem is there a way of getting around it? I made sure in creating the data table that it has only one row. I also tried binding only one row in the data table but a data table row isn't accepted as a data source. What's the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须添加
绑定字段
或设置DetailsViewAutoGenerateRows="true"
才能在详细信息视图中显示该字段。我确信你忘记这样做了..You have to add in a
Bound field
or Set the DetailsViewAutoGenerateRows="true"
to display the field in the detailsView. I am sure you forget to do this..DetailView.DataSource = DataSetName;
DetailView.DataMember = DataTableName;
http://www.dotnetspider.com/forum/319762-Datasource -Datamember-In-GridView.aspx
DetailView.DataSource = DataSetName;
DetailView.DataMember = DataTableName;
http://www.dotnetspider.com/forum/319762-Datasource-Datamember-In-GridView.aspx