if (e.Row.RowType == DataControlRowType.DataRow)
        {
e.Row.Attributes.Add("OnDblClick", "'"+this.TextBox3.Text+"'='" + e.Row.Cells[2].Text + "'");        }我想实现点击此行 把此行的一个字段或第三个单元格的值赋给this.TextBox3.Text上面的写法好像不对  上面第三个单元格 数据库里的字段名是ConsumerName

解决方案 »

  1.   

    LZ估计没有弄清楚前后台的区别吧。。你那样肯定不行啊。。要不触发后台事件来赋值。。要不得用JS的功能来赋值。。两种方法
      

  2.   

    两个一样的贴?
     <script language="javascript">
        function SetTextBox(text)//TextBox赋值
        {
        var txt=document.getElementById("TextBox1");
        txt.value=text;
        }
        </script>
            protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    e.Row.Attributes.Add("OnDblClick", "SetTextBox('" + e.Row.Cells[2].Text + "')");//添加JS事件            }         }
      

  3.   

    if ( e.Row.RowType == DataControlRowType.DataRow )
            {
                e.Row.Attributes.Add ( "OnDblClick", "document.getElementById('TextBox3').value='"+e.Row.Cells[2].Text+"'" );
            }这样可以