简体   繁体   English

在数据列表中动态更改一行的颜色

[英]Changing the color of one row dynamically in datalist

I have a button search, when the user clicks on the button it retrieves the data from a particular source and binds it to the datalist. 我有一个按钮搜索,当用户单击按钮时,它会从特定来源中检索数据并将其绑定到数据列表。

On this event, i need to change the color of a particular column, what column it exactly is will be defiened by the the checkboxes. 在这种情况下,我需要更改特定列的颜色,该复选框将确切定义它的确切列。

So my question is, is there a possibility to change the color of whole the column? 所以我的问题是,是否有可能改变整个色谱柱的颜色? Or do i need to do it cell per cell, and how to do that? 还是我需要在每个单元格中执行此操作,该怎么做? And if im doing it cell by cell how can i determine is this the right cell of a right column? 如果我按单元格进行操作,我如何确定这是右列的正确单元格?

Thanks in advance 提前致谢

Update: 更新:

I tried the way here was advised, but nothing happend, i dont know does it matter if all the data is in table inside the datalist? 我尝试了这里建议的方法,但是什么也没有发生,我不知道所有数据是否都在数据列表中的表中是否重要? It has any effect? 有什么作用吗?

FOUND SOLUTION: The best way to solve that is to add to the td in which you have the data id and the runat="server", this way you can then just in ItemDataBound execute the next code to get the cell: 找到的解决方案:最好的解决方法是将td添加到其中您具有数据ID和runat =“ server”,然后您可以在ItemDataBound中执行下一个代码以获取单元格:

(e.Item.FindControl("NameOfTheTD") as HtmlTableCell).BgColor = "Green";

Write the below code in the Datalist's ItemCommand 在数据列表的ItemCommand中编写以下代码

if (e.CommandName == "ThisMonth")
{
     System.Drawing.Color colour = System.Drawing.ColorTranslator.FromHtml("#65B3E3");
     e.Item.BackColor = colour;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM