这是定义的函数:
 Function write(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
        Text1.Value = e.Item.Cells(2).Text
 End Function下面的程序用到了函数:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
        If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
            e.Item.Attributes.Add("ondblclick", write(Me, e))
            e.Item.Attributes.Add("style", "cursor:hand")
            e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='lightblue'")
            e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
        End If
    End Sub最让我不明白的是,我把函数赋给了ondblclick属性,可当程序执行的时候(页面刚打开的时候),程序就自动执行了write函数,根本都不用我双击grid了,而且无论我双击那一条,程序都没有反应~
请问这是怎么回事啊?该怎么解决?

解决方案 »

  1.   

    你写的function是服务器端的代码,要写成客户端的才行。
      

  2.   

    e.Item.Attributes.Add
    里面的函数应该是js的
      

  3.   

    <script language =javascript >
    function write(sender As Object,e As DataGridItemEventArgs)
    {
       document.getElementById("Text1").innerText=e.Item.Cell(0).Text;
    }
    </script>这样改运行的时候出错~
      

  4.   

    好像意思是在dataGrid中点什么运行一点程序,可是这样做思路有点不对,如不考虑回发的问题可以用模版,在模版中的控件绑上这个事件就行了!将sender As Object,e As DataGridItemEventArgs参数修改一下就行了!不知道是不是这个问题?
      

  5.   

    不是这样的,我是让datagrid在web下模拟在winform下的选中效果,然后双击选中的row,触发函数,我不想用模板,谢谢~
      

  6.   

    <script language="javascript">
    function write(itemValue)
    {
         document.all.TextBox1.value = itemValue
    }
    </script>.vb文件中
    e.Item.Attributes.Add("ondblclick", "javascript:write("&e.Item.Cells(2).Text&")")
      

  7.   

    js没有write(sender As Object,e As DataGridItemEventArgs)
    这种事件写法
      

  8.   

    ________
    不是这样的,我是让datagrid在web下模拟在winform下的选中效果,然后双击选中的row,触发函数,我不想用模板
    ________
    如果是想调用服务器端的函数,只能是模拟button的回发函数
    示例如下
    在页面中加入一个LinkButton控件,Text="",在DataGrid的ItemDataBound中:
    if (e.Item.ItemIndex >= 0)
    {
      e.Item.Attributes["ondbClick"] = Page.GetPostBackClientHyperlink(LinkButton1, e.Item.ItemIndex);
    }
    然后在LinkButton1的Click中:
    DataGrid1.SelectedIndex = int.Parse(Request.Form["__EVENTARGUMENT"]);