为每个单元格加上onclick事件,单击并调用客服端tt函数
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            for (int i = 2; i < e.Row.Cells.Count - 1; ++i)
            {
                e.Row.Cells[i].Attributes.Add("onclick", "tt('"+e.Row.RowIndex+"','"+i+"')");
                e.Row.Cells[i].Attributes["style"] += "cursor:pointer;cursor:hand;";
            }
        }
    }
<script   language="javascript" >   
function tt(R,C)
{
(document.all["GridView1"]).Rows[R].Cells[C].add(document.all["TextBox1"]);
}
</script>  
错误提示:document.all.GridView1.Rows为空或者不是对象。
请问这样写错了哪里
还是不能这样用的。

解决方案 »

  1.   

    document.all["GridView1"]).Rows[R].Cells[C].add(document.all["TextBox1"]);这个有问题,你应该看浏览器中把那行解析成什么样子,然后在写。
    最好把解析出来的gridview也贴上看看。
      

  2.   

    document.all["TextBox1"]); 把这一串改成控件的HTML代码吧,<asp:TextBox ********>
      

  3.   

    <table cellspacing="0" rules="all" border="1" id="GridView1" style="border-collapse:collapse;">
    <tr>
    <th scope="col" style="width:1000px;">j</th><th scope="col" style="width:1000px;">jj</th><th scope="col" style="width:1000px;">d</th><th scope="col" style="width:1000px;">dd</th><th scope="col" style="width:1000px;">asd</th><th scope="col" style="width:1000px;">asdf</th>
    </tr><tr>
    <td>4</td><td>3</td><td onclick="tt('0','2')" style="cursor:pointer;cursor:hand;">222</td><td onclick="tt('0','3')" style="cursor:pointer;cursor:hand;">333</td><td onclick="tt('0','4')" style="cursor:pointer;cursor:hand;">888</td><td>&nbsp;</td>
    </tr><tr>
    <td>6</td><td>2</td><td onclick="tt('1','2')" style="cursor:pointer;cursor:hand;">333</td><td onclick="tt('1','3')" style="cursor:pointer;cursor:hand;">&nbsp;</td><td onclick="tt('1','4')" style="cursor:pointer;cursor:hand;">&nbsp;</td><td>&nbsp;</td>
    </tr><tr>
    <td>6</td><td>3</td><td onclick="tt('2','2')" style="cursor:pointer;cursor:hand;">5566</td><td onclick="tt('2','3')" style="cursor:pointer;cursor:hand;">&nbsp;</td><td onclick="tt('2','4')" style="cursor:pointer;cursor:hand;">&nbsp;</td><td>&nbsp;</td>
    </tr>
    </table>
      

  4.   

    解析出来的gridview
    的代码
      

  5.   

    我试了下:
        var table=document.all["GridView1"];
        table.rows[R].cell[C]这是存在的,但是table.rows[R].cell[C].add(document.all["TextBox1"])这个方法是不存在的 建议:可将该table.rows[].cell[]中单元格的值获取出来,然后修改该单元格的innerhtml   
      

  6.   

    谢谢6楼
    修改完后好像不能更新到服务器table.rows[R].cell[C].text
    页面重载后table.rows[R].cell[C].text的值变回原来的值
    绑定是在If(!ispostback){this.GridView1.DataBind();}中绑定的