我在更新面板中有一个网格视图,其中包含以下代码来选择一行,这反过来又使用表单记录中的详细信息更新另一个更新面板。
protected void gvMainGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Make the entire row clickable to select this record
//Uses javascript to post page back
e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
e.Row.Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(this.gvMainGrid, "Select$" + e.Row.RowIndex));
}
}
我正在从数据库手动绑定 gridview,并且不想重新绑定网格只是为了突出显示该行,但我似乎无法向 onclick 事件添加任何 javascript,它似乎要么显示 GetPostBackClientHyperlink 要么显示行突出显示JavaScript。
如何在选择行时突出显示gridview http://www.netomatix.com/development/GridViewRowSelectedStyle.aspx
为此,您必须在 OnRowCreated 事件的代码隐藏文件中编写此代码,或者您也可以在网格的 OnRowDataBound 事件中编写此代码...
protected void ctlGridView_OnRowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "onGridViewRowSelected('" + e.Row.RowIndex.ToString() + "')");
}
}
并添加这个脚本
<script language="javascript" type="text/javascript">
var gridViewCtlId = '<%=ctlGridView.ClientID%>';
var gridViewCtl = null;
var curSelRow = null;
function getGridViewControl()
{
if (null == gridViewCtl)
{
gridViewCtl = document.getElementById(gridViewCtlId);
}
}
function onGridViewRowSelected(rowIdx)
{
var selRow = getSelectedRow(rowIdx);
if (curSelRow != null)
{
curSelRow.style.backgroundColor = '#ffffff';
}
if (null != selRow)
{
curSelRow = selRow;
curSelRow.style.backgroundColor = '#ababab';
}
}
function getSelectedRow(rowIdx)
{
getGridViewControl();
if (null != gridViewCtl)
{
return gridViewCtl.rows[rowIdx];
}
return null;
}
</script>
它将突出显示所选行..
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)