如何修改中继器以不显示绑定到它的每一行的数据?
本文关键字:一行 数据 显示 修改 何修改 中继器 绑定 | 更新日期: 2023-09-27 18:17:22
我有一个存储过程,它返回表中的4行。每一行对应一个人在酒店住了一天,所以当我绑定一个中继器时,会显示4行。其中两排是同一个房间,另外两排是同一个房间。我想显示信用卡信息,但不是每个单独的房间,而是每组相同的房间,所以它看起来像这样:
12/7/2011房间1
12/8/2011房间1
信用卡信息
12/7/2011房间2
12/8/2011房间2
信用卡信息
我不想将房间信息和信用信息分别合并到一行中。我怎样才能把它格式化成我想要的样子呢?
目前我在一个ItemTemplate中显示房间信息,ItemTemplate中是一个tr和td。
您基本上有两个选择:您可以预处理数据,以便绑定到中继器的内容代表您想要呈现给用户的内容- DJ KRAZE已经展示了一种方法。
另一种选择是添加ItemDataBound事件处理程序,并在该点操作数据和/或当前行。
//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..