一个关于DataList的问题,高分求解!!(C#)
假设有个DataList共有三个数据列(编号、姓名、地址),并且该DataList的Header中有三个LinkButton,其Text属性分别就为“编号、姓名、地址”。比如当用鼠标点击Text属性为“编号”的LinkButton后,将产生OnItemCommand事件,该事件对应的处理方法假设为DataList1_ItemCommand((object source, System.Web.UI.WebControls.DataListCommandEventArgs e).
那么请问,在DataList1_ItemCommand()方法的执行代码中,如何实现DataList的所有DataListItem中与Header中“编号”列对应的所有编号信息均改变底色进行突出显示呢?感觉上就象通过点击标头使得数据表中与该标头对应的整列信息都被突出显示的效果那样。
谢谢指教!!
问题点数:100、回复次数:7Top
1 楼camelials(星期五)回复于 2003-12-04 18:38:42 得分 0
我得试试才知道。感觉这样挺好玩的。
应该不难实现。
先帮你UP一下。
Top
2 楼gordenfl(笨笨(杨过寻找姑姑,两行泪....))回复于 2003-12-04 18:43:29 得分 0
学习
upTop
3 楼crodling(十方)回复于 2003-12-04 18:59:43 得分 30
刚才用DataGrid写了这么一段代码,只是有局限性,如果有两列是相同的话就不行了,而且是在排序是建里面处理的,DataList应该也差不多可以根据连接按钮传递字符串,对相应进行类似处理吧?
private void MyDataGrid_Sort(Object sender, DataGridSortCommandEventArgs e)
{
int j=0;
for (j=0;j<MyDataGrid.Columns.Count;j++)
if (e.SortExpression==MyDataGrid.Columns[j].SortExpression)
{
break;
}
for (int i=0;i<MyDataGrid.Items.Count;i++)
{
MyDataGrid.Items[i].Cells[j].BackColor=System.Drawing.Color.Black;
}
}Top
4 楼saucer(思归)回复于 2003-12-04 19:52:10 得分 70
how did you bind the data? seems to me, you should be using DataGrid, this way, you can try something like
foreach(DataGridItem dgi in DataGrid1.Items)
{
dgi.Cells[n].BackColor=Color.Red;
}
otherwise, you need to bind your three pieces of data to different controls, and try something like
foreach(DataListItem dli in DataList1.Items)
{
Label lbl = (Label)dli.FindControl(YourControlIDDependingOnYourSelection);
lbl.BackColor = Color.Red;
}Top
5 楼myblueeye(蓝眼睛)回复于 2003-12-05 10:31:54 得分 0
谢谢回复,用DataGrid是可以实现,但是现在想知道DataList是否也可以,通过saucer兄的:
foreach(DataListItem dli in DataList1.Items)
{
Label lbl = (Label)dli.FindControl(YourControlIDDependingOnYourSelection);
lbl.BackColor = Color.Red;
}
虽然可以做到,但是由于每个Label的高度并不能与“<tr>”的一致,所以将出现Label的BackColor与"<td>"的背景色不一致的情况,出现色彩间隙!Top
6 楼myblueeye(蓝眼睛)回复于 2003-12-08 09:37:15 得分 0
upTop
7 楼saucer(思归)回复于 2003-12-08 09:45:38 得分 0
try to set the label's Height to Unit.Percentage(100), or try to set the underlying "<TD>" colorTop




