如何在Asp.net Web应用程序中更改gridview选定的项目背景颜色?如何更改gridview选定的项目背景颜色?
2
A
回答
0
你可以尝试调用JavaScript本功能离子在onmouseover
事件。 This website有一个简单的例子:
在服务器端:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] =
"javascript:mouseovercolor(this);";
e.Row.Attributes["onmouseout"] =
"javascript:mouseoutcolor(this);";
}
}
在客户端:
<script language=javascript type="text/javascript">
function mouseovercolor(mytxt) {
mytxt.bgColor = 'Orange';
}
function mouseoutcolor(mytxt) {
element.bgColor = 'White';
}
</script>
编辑:This site has a nice example如何使其与onClick
事件工作:
服务器端:
protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e){
if (e.Row.RowType == DataControlRowType.DataRow){
// javascript function to call on row-click event
e.Row.Attributes.Add("onClick", "javascript:void SelectRow(this);");
}
}
客户端:
<script type="text/javascript">
// format current row
function SelectRow(row) {
var _selectColor = "#303030";
var _normalColor = "#909090";
var _selectFontSize = "3em";
var _normalFontSize = "2em";
// get all data rows - siblings to current
var _rows = row.parentNode.childNodes;
// deselect all data rows
try {
for (i = 0; i < _rows.length; i++) {
var _firstCell = _rows[i].getElementsByTagName("td")[0];
_firstCell.style.color = _normalColor;
_firstCell.style.fontSize = _normalFontSize;
_firstCell.style.fontWeight = "normal";
}
}
catch (e) { }
// select current row (formatting applied to first cell)
var _selectedRowFirstCell = row.getElementsByTagName("td")[0];
_selectedRowFirstCell.style.color = _selectColor;
_selectedRowFirstCell.style.fontSize = _selectFontSize;
_selectedRowFirstCell.style.fontWeight = "bold";
}
</script>
2
你可以做的是在GridView标签下的aspx页面:
<SelectedRowStyle BackColor="Orange" />
但是,如果你想在鼠标或鼠标不同的颜色了,然后尝试背后下RowDataBound事件中的代码下面
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand';this.style.backgroundColor='orangered'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
}
}
还检查了这个链接,如果你想选择一个行不点击的按钮:ASP.NET: Selecting a Row in a GridView
相关问题
- 1. 如何更改LongListSelecter中选定项目的背景颜色?
- 2. 如何更改Windows Phone中选定项目的背景颜色?
- 3. 如何更改ListView中选定项目的背景颜色?
- 4. 如何更改telerik radrotator选定项目的背景颜色
- 5. 如何更改项目的背景颜色由一个选项
- 6. 我如何更改jtabbedpane选定的选项卡背景颜色
- 7. ListView的项目更改背景颜色
- 8. 如何更改ListView所选项目的背景颜色?
- 9. 滚动GridView并更改项目网格中的背景颜色
- 10. 在gridview中更改背景颜色的项目触摸
- 11. 更改列表框中选定项目的背景颜色
- 12. 更改选定列表框项目的背景颜色
- 13. 更改Android Spinner中选定项目的背景颜色
- 14. onItemClick选项更改背景颜色
- 15. 更改TabLayout的选定选项卡背景和文本颜色
- 16. 如何将recyclerView项目背景颜色更改为阴影白色背景?
- 17. ComboBox的风格背景颜色,以匹配选定的项目背景颜色
- 18. 如何更改qtablewidget项目的qtooltip的背景颜色?
- 19. 更改recyclerview中所选项目的背景颜色
- 20. 如何更改aspxgridexporter gridview的背景色
- 21. 如何更改ListView项目的背景颜色?
- 22. 如何更改微调项目中文本的背景颜色?
- 23. 如何更改listview中每个项目的背景颜色?
- 24. 如何更改ListView项目中的背景颜色?
- 25. 如何更改ListView中多个项目的背景颜色
- 26. 如何在悬停时更改ListBox项目的背景颜色?
- 27. 如何更改悬停ul列表项目的背景颜色
- 28. 当选择特定选项时更改背景颜色
- 29. 如何更改选项菜单的背景颜色?
- 30. 如何更改PhpStorm中活动选项卡的背景颜色?
谢谢,但我有这个错误,当我调试它:错误只有内容控件被允许直接在包含内容控件的内容页面。 – Gandhi 2012-04-22 15:08:56
你在使用母版页吗?如果是这样,只是为了排除故障,将javascript块移到母版页(头标记) – Ulises 2012-04-22 15:14:34
感谢我的朋友的帮助,但是当我单击网格视图中的另一个单元格时,我想重置前一个单元格的值并应用新细胞的新价值。 – Gandhi 2012-04-22 15:29:50