//保存当前的高亮行的数据
var objLastRow //上一个行对象
var szLastRowClassName //上一个行对象的Style名称
var nCurrentRow = -1 //当前行的行数
function setRowFocus(objRow,bIsFirstSet,nRow){
if (!bIsFirstSet){
objLastRow.className = szLastRowClassName ;
}
objLastRow = objRow ;
szLastRowClassName = objRow.className ;
objRow.className = 'ListTableRowHighlight' ;
nCurrentRow = nRow ;
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if(e.Item.ItemIndex != -1 )
{
//取得当前项的索引值加1,因为项的索引值是从0开始的.
int row = e.Item.ItemIndex+1;
e.Item.Attributes.Add("id","Row"+row.ToString());
e.Item.Attributes.Add("onClick","setRowFocus(this,false,"+row.ToString()+" );");
}
}
}
3.在html的增加<hand><SCRIPT src="../css/FunDefine.js" type="text/javascript"></SCRIPT> </hand>4.在</from>前面增加
<script LANGUAGE="javascript">
<!--
var RowsCount=DataGrid1.rows.length;
if(RowsCount>=2)
setRowFocus(Row1,true,0) ;
//-->
</script>