您的位置:首页 > Web前端 > HTML

单击选中GridView 或 HTML 表格的某行,并获取该行的数据。。。。

2011-09-21 18:00 423 查看
首先绑定行单击事件,如下:也可以用Jquery的.click进行事件绑定

protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e){
if (e.Row.RowType == DataControlRowType.DataRow){

e.Row.Attributes.Add("onClick", "javascript:void SelectRow(this);");
}
}


然后再前台页面head部分写如下函数:

<script type="text/javascript">
// 对选中行的处理函数
function SelectRow(row) {
var _selectColor = "#303030";
var _normalColor = "#909090";
var _selectFontSize = "3em";
var _normalFontSize = "2em";
// 获取当前行的所有数据单元
var _rows = row.parentNode.childNodes;
// 获取数据
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) { }
// 对该行的第一个单元格设样式
var _selectedRowFirstCell = row.getElementsByTagName("td")[0];
_selectedRowFirstCell.style.color = _selectColor;
_selectedRowFirstCell.style.fontSize = _selectFontSize;
_selectedRowFirstCell.style.fontWeight = "bold";
}
</script>


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息