首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修改中继器以不显示绑定到它的每一行的数据?

如何修改中继器以不显示绑定到它的每一行的数据?
EN

Stack Overflow用户
提问于 2011-12-08 03:41:32
回答 2查看 465关注 0票数 0

我有一个存储的proc,它返回表中的4行。每一行对应于一个人住在酒店的一天,所以当我给它绑定一个中继器时,就会显示4行。其中两排是同一个房间,另外两排是同一个房间。我想要显示信用卡信息,但不是每个单独的房间,而是每组相同的房间,所以它看起来像这样:

2011年12月7日1号展厅

2011年12月8日1号房间

信用卡信息

2011年12月7日2号房间

2011年12月8日2号房间

信用卡信息

我不想将房间信息和信用信息合并到一行中。我怎样才能让它按照我想要的方式格式化呢?

目前,我在ItemTemplate中显示房间信息,ItemTemplate内部是tr和td。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-12-08 04:28:32

代码语言:javascript
复制
//Create either a HashTable() 
//or a Dictionary<int, string[]> I would personally use a Dictionary<> 

//create an instance of what ever collection you want to use or array
  //List<string>
  //Dictionary<int, string[]>() using the room number as the key
  // you would add the values to either the List<> or a String[] array or a Dictionary
keey in mind that if you want to create a dynamic string[] array and you do not know how many elements you are going to add just use a List<> or Dictionary<int,string>
and you can always convert that object using .ToArray 
so for example 


List<string> lstRoomList = new List<string>();
string[] arrayRoom = {};
if you have a DataReader for example and you are doing something like 
while (yourdataReader.Read())
{
  // here you can decide how you are going to work with the data you 
  lstRoomList.Add(datareader["roomnubmer"] + " " + datareader[CreditCarInfo];
}
at the end you could assign the values of that list to a dynamic array
arrayRoom = kstRoomList.ToArray(); I would really need to see what you are using and how you are returning the StoredProc results..
票数 -2
EN

Stack Overflow用户

发布于 2011-12-08 04:37:31

你基本上有两个选择:你可以对数据进行预处理,以便绑定到中继器的内容代表你想要呈现给用户的内容- DJ KRAZE已经展示了一种方法。

另一种选择是添加一个ItemDataBound event handler,并在该点操作数据和/或当前行。

第二种方法的一个缺点是,您需要访问前一行才能做出决策-这可能会使事情变得复杂,特别是当您对结果进行分页时。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8421464

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档