用datagrid绑定的记录,用上下键,在记录上移动(高亮显示),高亮显示的行,为选中的行,按回车键,把选中的行的第一单元格和第二单元格的值以参数形式传递到父页面。高手都来看一下啊。

解决方案 »

  1.   

    父窗体a打开b
     function OpenSelect()
    {
      window.showModalDialog("b.aspx",window,"dialogWidth:800px;DialogHeight=600px;status:no");
        }b得到记录并传值给父窗体a:
    function SelectItem(company)
        { 
             if (window.dialogArguments != null) 
         {
       var parwin = window.dialogArguments;
          
           if(parwin.document.all.FEditFrm != null)
           {
                  parwin.document.all.FEditFrm.txtcompany.value = escape(company);
                  }
               
           window.close();
        }
    其中FEditFrm 为a的form的id <form id="FEditFrm " runat="server">;txtcompany为得值的控件id。
      

  2.   

    我写过一个,楼主改一下应该可以用
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
        <head>
            <style>
                .lightrow{color:red;}
            </style>
            <script language="javascript">
            var lightCss = "lightrow";
            var curRow = null;
            function keyDown()
            {
                var key = event.keyCode;
                var obj = curRow;
                switch(key)
                {
                    case 13://Enter key //这里操作改一下就可以
                        obj.cells[0].childNodes[0].checked = !obj.cells[0].childNodes[0].checked;
                        alert("current RowIndex:"+obj.rowIndex+"\nID:"+obj.cells[1].innerText);
                        break;
                    case 38://up key
                        if(obj.rowIndex>1)
                        {
                            curRow.className = "";
                            curRow=obj.previousSibling;
                            curRow.className = lightCss;
                        }
                        break;
                 
                    case 40://down key
                        if(obj.rowIndex<obj.parentNode.rows.length-1)
                        {
                            curRow.className = "";
                            curRow=obj.nextSibling;
                            curRow.className = lightCss;
                        }
                        break;
                }
            }
            document.onkeydown=keyDown;
            window.onload=function()
            {
                var tbl = document.getElementById("tbl");
                curRow = tbl.rows[1];
                curRow.className = lightCss;
            };
            </script>
        </head>
        <body>
        
            <table width="300px" style="background-color:#000" border="0" id="tbl" cellpadding=0 cellspacing=1>
                <tr style="background-color:#fff">
                    <th></th>
                    <th>ID</th>
                    <th>NAME</th>
                </tr>
                <tr style="background-color:#fff">
                    <td><input type="checkbox" /></td>
                    <td>1</td>
                    <td>a1</td>
                </tr>
                <tr style="background-color:#fff">
                    <td><input type="checkbox" /></td>
                    <td>2</td>
                    <td>a2</td>
                </tr>
                <tr style="background-color:#fff">
                    <td><input type="checkbox" /></td>
                    <td>3</td>
                    <td>a3</td>
                </tr>
            </table>
        </body>
    </html>
      

  3.   

    我改了一下,支持循环移动,url也帮你加了,ONKEYDOWN事件限制在table上
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
        <head>
            <style>
                .lightrow{color:red;}
            </style>
            <script language="javascript">
            var lightCss = "lightrow";
            var curRow = null;
            function keyDown(url)
            {
                var key = event.keyCode;
                var obj = curRow;
                switch(key)
                {
                    case 13://Enter key 
                        //obj.cells[0].childNodes[0].checked = !obj.cells[0].childNodes[0].checked;
                        //alert("current RowIndex:"+obj.rowIndex+"\nID:"+obj.cells[1].innerText);
                        alert(url+"?id="+obj.cells[0].innerText+"&name="+obj.cells[1].innerText);
                        break;
                    case 38://up key
                        curRow.className = "";
                        if(obj.rowIndex>1)
                        {
                            curRow=obj.previousSibling;
                            
                        }else
                        {
                            curRow=obj.parentNode.childNodes[obj.parentNode.childNodes.length-1];
                        }
                        curRow.className = lightCss;
                        break;
                 
                    case 40://down key
                        curRow.className = "";
                        if(obj.rowIndex<obj.parentNode.rows.length-1)
                        {
                            curRow=obj.nextSibling;
                        }else
                        {
                            curRow=obj.parentNode.childNodes[1];
                        }
                        curRow.className = lightCss;
                        break;
                }
            }        window.onload=function()
            {
                var tbl = document.getElementById("tbl");
                curRow = tbl.rows[1];
                curRow.className = lightCss;
                var url="http://localhost/aa.aspx";
                tbl.onkeydown = function()
                {
                    keyDown(url);
                }
            };
            </script>
        </head>
        <body>
        
            <table width="300px" style="background-color:#000" border="0" id="tbl" cellpadding=0 cellspacing=1>
                <tr style="background-color:#fff">
                    <th>id</th>
                    <th>name</th>
                    <th>desc</th>
                </tr>
                <tr style="background-color:#fff">
                    <td>01</td>
                    <td>1</td>
                    <td>a1</td>
                </tr>
                <tr style="background-color:#fff">
                    <td>02</td>
                    <td>2</td>
                    <td>a2</td>
                </tr>
                <tr style="background-color:#fff">
                    <td>03</td>
                    <td>3</td>
                    <td>a3</td>
                </tr>
            </table>
        </body>
    </html>
      

  4.   

    支持楼上,根据楼上的改成gridview的。
    后台:
    public partial class testGrid : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.GridView1.DataSource = this.TestData;        this.GridView1.DataBind();
        }    /// <summary>
        /// 测试数据源
        /// </summary>
        private DataTable TestData
        {
            get
            {
                DataTable dt = new DataTable();
                dt.Columns.Add(new DataColumn("ID", typeof(int)));
                dt.Columns.Add(new DataColumn("Name", typeof(string)));            dt.Rows.Add(new object[] { 1, "湖北" });
                dt.Rows.Add(new object[] { 2, "江苏" });
                dt.Rows.Add(new object[] { 3,  "浙江" });
                dt.Rows.Add(new object[] { 4,  "黄冈" });
                return dt;
            }
        }}前台。
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="testGrid.aspx.cs" Inherits="testGrid" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
            <style>
                .lightrow{color:red;}
            </style>
            <script language="javascript">
            var lightCss = "lightrow";
            var curRow = null;
            function keyDown()
            {
                var key = event.keyCode;
                var obj = curRow;
                switch(key)
                {
                    case 13://Enter key //这里操作改一下就可以
                  
                        alert("ID:"+obj.cells[0].innerText+"\nName"+obj.cells[1].innerText);
                        break;
                case 38://up key
                        curRow.className = "";
                        if(obj.rowIndex>1)
                        {
                            curRow=obj.previousSibling;
                            
                        }else
                        {
                            curRow=obj.parentNode.childNodes[obj.parentNode.childNodes.length-1];
                        }
                        curRow.className = lightCss;
                        break;
                 
                    case 40://down key
                        curRow.className = "";
                        if(obj.rowIndex<obj.parentNode.rows.length-1)
                        {
                            curRow=obj.nextSibling;
                        }else
                        {
                            curRow=obj.parentNode.childNodes[1];
                        }
                        curRow.className = lightCss;
                        break;            }
            }
            document.onkeydown=keyDown;
            window.onload=function()
            {
                var tbl = document.getElementById("GridView1");
                curRow = tbl.rows[1];
                curRow.className = lightCss;
            };
            </script>
        </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server">
            </asp:GridView>
        
        </div>
        </form>
    </body>
    </html>
      

  5.   

    这个不算很难吧,lz你不做winform程序可惜了;
    尽量不要拿winform程序的操作习惯来套web程序,不然你会吃力不讨好的
      

  6.   

    a.aspx (父页)
    ---------------------------
    ...
    var o = window.showModalDialog("b.aspx", ...); 
    // 处理弹出页返回的数据
     //alert(o.cell1);
     //alert(o.cell2);b.aspx (弹出页)
    ---------------------------
    // 处理快捷键部分略..
    var x = new Object();
    x.cell1 = 取到第一列的值赋上;
    x.cell2 = 取到第二列的值赋上;
    returnValue = x;
    window.close();
    楼主再自己完善下应该是可以用的..