2009-10-20 43 views
0

我有一个gridview附加到objectdatasource。在每一行中,我都有一个用于输入的绑定文本框。我在每行的文本框旁边都有一个按钮,用于启动单位转换的JavaScript弹出窗口。
问题是:我如何告诉单位转换器(js函数)什么文本框(在哪一行)填充结果?在GridView中引用项目

回答

0

在GridView的RowCreated事件:

Protected Sub MyGridView_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles MyGridView.RowCreated 
    If e.Row.RowType = DataControlRowType.DataRow Then 
     Dim btn As Button = e.Row.Cells(0).FindControl("btnJavaScriptButton") 
     Dim txt As TextBox = e.Row.Cells(1).FindControl("txtResults") 

     btn.OnClientClick = "calculate(" & txt.ClientID & ");" 
    End If 
End Sub 

其中0和1是包含按钮和文本框列的索引,和“算”是你的JavaScript函数的名称。