在OnItemCreated的Repeater中获取列名 [英] Getting a column name in a Repeater in OnItemCreated

查看:105
本文介绍了在OnItemCreated的Repeater中获取列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一种Repeater,该Repeater从具有如下布局的表中读取数据:

I am working on a Repeater that reads from a table with a layout something like:

string Title
string Location
bool Water
bool Sewer
bool Picnic_Table
bool On_Beach
...

我正在为每个标题"创建便利设施列表,因此我需要遍历各列并获取每个标题(或站点)的便利设施列表.理想情况下,我有一个遍历列表的循环.像

I am creating a list of amenities for each "Title" so I need to loop through the columns and get a list of amenities for each Title (or site). Optimally, I have a loop to go through the list. Something like

for each column
   if column is not Title or Location
      Append to StringBuilder "column name"

如何获取该列名进行比较?

How do I get that column name to do the comparisons?

推荐答案

以下是在Repeater控件的OnItemCreated事件中获取列名的方法:

Here's how to get the column name in the OnItemCreated event of the Repeater control:

protected void rptOnItemCreated_OnItemCreated(object sender, RepeaterItemEventArgs e)
{
    string columnName = string.Empty;
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        DataRowView drv = (DataRowView)e.Item.DataItem;
        DataRow dr = drv.Row;
        foreach (DataColumn dc in dr.Table.Columns)
        {
            // Do what you want with the column name
            columnName = dc.ColumnName;
        }
    }
}

这篇关于在OnItemCreated的Repeater中获取列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆