views:

173

answers:

1

hi guys, I have a datagrid.Its 1st column is ClientType.On clicking each cell in the first column i.e ClientType,that value is shown in textbox named txtClientType.For that i used the following code.

Private Sub dtGridsearch_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dtGridsearch.ItemDataBound
    Dim lt As ListItemType = e.Item.ItemType
    If lt = ListItemType.Item Or lt = ListItemType.AlternatingItem Then
        Dim currentCell As TableCell = CType(e.Item.Controls(0), TableCell)
        dtGridsearch.Columns(0).InitializeCell(currentCell, 0, ListItemType.Item)
        Dim s As New System.Web.UI.WebControls.Style
        s.CssClass = "Hyp"
        Dim str As String = CType(e.Item.DataItem, DataRowView).Row(1)
        currentCell.ApplyStyle(s)
        currentCell.Attributes.Add("OnClick", "javascript:PassBack('" & CType(e.Item.DataItem, DataRowView).Row(0) & "','" & str.Trim & "');")
    End If
End Sub

In javascript i used following code to bind value to textbox function PassBack(FieldId,FieldValue) {

      document.getElementById(txtClientType).value = FieldValue;

}

The above codes are working in IE.But in chrome when i click cell in datagrid corresponding value is not coming in textbox.Iam using VS2008.What may be the reason?Can anybody help?

A: 

First: "javascript:" is invalid javascript, it is a protocol directive, if you were assigning an href attribute to an A tag, this would be appropriate.

Second: try "onclick" instead of "OnClick"

Third: You can probably handle this data binding in your row template tag...

<asp:Button ... OnClientClick="PassBack('<%#Eval(...)%>','<%#Eval(...)%>'); return false;" .../>

Fourth you should probably have a " return false;" after your PassBack call, to prevent the default handler from triggering.

Tracker1