zoukankan      html  css  js  c++  java
  • JS控制GridView行选择

    ASP.NET里的GridView控件使用非常广泛,虽然其功能强大,但总有一些不尽如人意的地方。
    比如在选择行的时候,它就没有UltraWebGrid做的友好;UltraWebGrid允许用户设置是否显示选择框,设置允许,则会在最左边多出一列,表示选择的行。而GridView则没有这个功能。但没有,不代表不能实现,下面我就通过JS来实现行选择的标识。

    后台代码:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    ...{
        int id = Convert.ToInt32(InstallandMaintanceGrid.DataKeys[e.Row.RowIndex].Value.ToString());
        e.Row.Attributes.Add("ondblclick", "javascript:dbClick(" + id + ")");
        e.Row.Attributes.Add("id", _i.ToString());
        e.Row.Attributes.Add("onKeyDown", "SelectRow();");
        e.Row.Attributes.Add("onClick", "MarkRow(" + _i.ToString()+","+id + ");");
        _i++;
    }

    前台代码:

     <script type="text/javascript">
                function dbClick(keys)...{
                    //双击,获取该行ID
                    document.getElementById("ctl00_hd_selectedid").value = keys;
                }
                var currentRowId = 0;    
                function SelectRow()//选择行
                ...{
                    if (event.keyCode == 40)
                        MarkRow(currentRowId+1);
                    else if (event.keyCode == 38)
                        MarkRow(currentRowId-1);
                }        

                function MarkRow(rowId,keys)//选中行变色
                ...{
                    if (document.getElementById(rowId) == null)
                        return;            
                    if (document.getElementById(currentRowId) != null )
                    ...{
                        document.getElementById(currentRowId).style.backgroundColor ='#ffffff';
                    }

                    currentRowId = rowId;
                    document.getElementById(rowId).style.backgroundColor = '#ff0000';
                    document.getElementById("ctl00_hd_selectedid").value = keys;
                }
            </script>

    --------------------- 本文来自 zsj830120 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/zsj830120/article/details/2408422?utm_source=copy 

  • 相关阅读:
    windows下 文件资源管理器 的操作
    Visual Studio Code 折叠代码快捷键
    windows 10 取消alt+tab的预览功能
    String.prototype.replace
    Webpack的tapable 为什么要使用 new Funtion 来生成静态代码
    Visual Studio Code 断点调试Nodejs程序跳过node内部模块(internal modules)
    【社群话题分享】有哪些奇葩的技术人员考核方式?
    工信部要求应用商店上新 App 检查 IPv6,这里有一份 IPv6 快速部署指南
    读完这篇文章,5G 就没有秘密了
    双剑合璧——掌握 cURL 和 Dig 走天涯
  • 原文地址:https://www.cnblogs.com/asdyzh/p/9750660.html
Copyright © 2011-2022 走看看