Hi all, I am trying to execute a javascript a code if the DataGrid cell item changes. The Grid itself has server side asp:textbox control inside the itemTemplate. Basically when the user clicks on a Go Button, the Grid is rendered. Inside the Go event handler,
I have tried this -
Private Sub btnGO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGO.ServerClick
BindGrid()
RenderJavaScript()
Page.DataBind()
End Sub
Public Sub BindGrid()
datagrid1.DataSource = objGrid.ProjectData.Tables(0).DefaultView
datagrid1.DataBind()
End Sub
Private Sub RenderJavaScript()
Dim dgi As DataGridItem
Dim i As Integer
For i = 0 To datagrid1.Items.Count - 1
dgi = datagrid1.Items(i)
pr1 = CType(dgi.FindControl("pr1"), TextBox)
pr2 = CType(dgi.FindControl("pr2"), TextBox)
pr3 = CType(dgi.FindControl("pr3"), TextBox)
pr1.Attributes.Add("onchange", "ChangeHour(this.name,this.value);")
pr2.Attributes.Add("onchange", "ChangeHour(this.name,this.value);")
pr3.Attributes.Add("onchange", "ChangeHour(this.name,this.value);")
Next
End Sub
The RenderJavaScript Method is called when the user clicks on Go button to bind javascript code the datagrid columns cells. The grid items loop fine but its not adding the attributes to the asp:textbox controls. I cannot call RenderJavaScript
on PageLoad as the Datagrid is hidden, in other words there are no controls added to the page on page_load event. I appreciate your assistance.
Hi, I am attaching a confirmation message to the deletebutton in a datagrid as show below. Try doing the same for your textbox change also...
Dim btnDelete As LinkButton ' Link Button Type
Try
' Check if DEAR components Screen's CanDelete Attribute is True
If mObjDEAR.Screen.CanDelete = True Then
' If ItemType is ListItemType's Item or ALternatingItem
If e.Item.ItemType = ListItemType.Item _
Or e.Item.ItemType = ListItemType.AlternatingItem Then
' Typecast the LinkButton and Set Confirmation message to the button
btnDelete = CType(e.Item.Cells(0).FindControl("cmdDel"), LinkButton)
btnDelete.Attributes.Add("onclick", "return confirm('Do you want to delete record?');")
End If
End If
Catch ex As Exception
setMessage(ex.Message(), MessageTypes.ErrorType)
End Try
deadhead
Member
55 Points
11 Posts
Execute Javascript when DataGrid cell changes
Oct 23, 2003 07:23 PM|LINK
Private Sub btnGO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGO.ServerClick BindGrid() RenderJavaScript() Page.DataBind() End Sub Public Sub BindGrid() datagrid1.DataSource = objGrid.ProjectData.Tables(0).DefaultView datagrid1.DataBind() End Sub Private Sub RenderJavaScript() Dim dgi As DataGridItem Dim i As Integer For i = 0 To datagrid1.Items.Count - 1 dgi = datagrid1.Items(i) pr1 = CType(dgi.FindControl("pr1"), TextBox) pr2 = CType(dgi.FindControl("pr2"), TextBox) pr3 = CType(dgi.FindControl("pr3"), TextBox) pr1.Attributes.Add("onchange", "ChangeHour(this.name,this.value);") pr2.Attributes.Add("onchange", "ChangeHour(this.name,this.value);") pr3.Attributes.Add("onchange", "ChangeHour(this.name,this.value);") Next End SubThe RenderJavaScript Method is called when the user clicks on Go button to bind javascript code the datagrid columns cells. The grid items loop fine but its not adding the attributes to the asp:textbox controls. I cannot call RenderJavaScript on PageLoad as the Datagrid is hidden, in other words there are no controls added to the page on page_load event. I appreciate your assistance.venumg
Contributor
2325 Points
465 Posts
Re: Execute Javascript when DataGrid cell changes
Oct 23, 2003 07:44 PM|LINK
Dim btnDelete As LinkButton ' Link Button Type Try ' Check if DEAR components Screen's CanDelete Attribute is True If mObjDEAR.Screen.CanDelete = True Then ' If ItemType is ListItemType's Item or ALternatingItem If e.Item.ItemType = ListItemType.Item _ Or e.Item.ItemType = ListItemType.AlternatingItem Then ' Typecast the LinkButton and Set Confirmation message to the button btnDelete = CType(e.Item.Cells(0).FindControl("cmdDel"), LinkButton) btnDelete.Attributes.Add("onclick", "return confirm('Do you want to delete record?');") End If End If Catch ex As Exception setMessage(ex.Message(), MessageTypes.ErrorType) End TryCheers,
Venugopal Mallarapu.
Visit : My Blog
deadhead
Member
55 Points
11 Posts
Re: Execute Javascript when DataGrid cell changes
Oct 23, 2003 09:20 PM|LINK
venumg
Contributor
2325 Points
465 Posts
Re: Execute Javascript when DataGrid cell changes
Oct 24, 2003 01:41 PM|LINK
Cheers,
Venugopal Mallarapu.
Visit : My Blog