获取 DataList 中的行名称
我有一个数据列表,想从表中提取行名称,我从中获取数据列表的值。这是我想做的一个例子。
<HeaderTemplate>
'Get data row names
'Maybe something like Container.DataItem(row)?
</HeaderTemplate>
I have a datalist and would like to pull the row names from the table that I am getting my values from for the datalist. Heres an example of what I would like to do.
<HeaderTemplate>
'Get data row names
'Maybe something like Container.DataItem(row)?
</HeaderTemplate>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 DataTable 作为数据列表的数据源,则可以使用
OnItemCreated
方法并为ItemCreated
事件提供自定义处理程序以添加列标题值。我不确定你为什么要这样做。听起来像 Repeater 或GridView 可能更适合您的需求。无论如何,这是代码。If you are using a DataTable as a Data Source for your Data List you could use the
OnItemCreated
method and provide a custom handler for theItemCreated
event to add the column header values. I'm not sure why you would want to do this. It sounds like a Repeater or GridView might be better suited to your needs. At any rate, here's the code.您可以执行以下操作,但我怀疑它是否有效。我不相信创建标题时数据项可用。
如果这有效,您可以循环访问此集合并检查每个项目的 ColumnName 属性。
更好的想法是:
List
。当您声明标头时,您可以在标记中引用此属性。You could do the following, but I doubt it would work. I don't believe DataItems are available at the point when the Header is being created.
If this works, you can loop through this collection and inspect each item's ColumnName property.
A better idea would be to either:
List<string>
of appropriate column headers. You can refer to this property in markup when you're declaring the header.