Torna al Thread
'Variabile d'appoggio
Private BodyScript As String = ""
'Nel PreRender inserisco le righe script generate dall' evento RowDataBound di GridView1
Protected Sub GridView1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PreRender
If _clientScript Is Nothing Then
_clientScript = New Literal()
_clientScript.Visible = False
Else
_clientScript.Text = "<script type=""text/javascript"">" + vbCrLf + BodyScript + "</script>" + vbCrLf
End If
End Sub
'Viene chiamata per ogni row del datagrid
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim drv As DataRowView = CType(e.Row.DataItem, DataRowView)
Const Title As String = "Dettagli" ' se titolo e' vuoto da una tips senza titolo.
If drv IsNot Nothing Then
' Carico i dati per il dataview
Dim ob As Object = drv("ID")
Dim imm As New sm.Db.Helpers.IMMOBILI
imm.LoadByPrimaryKey(CInt(drv("ID")))
'Definisco l'array Text (javascript) e lo aggiungo nella variabile BodyScript
'per poi inserirla in _clientScript tramite l'evento PreRender del datagrid
BodyScript += addTextTips(e.Row.DataItemIndex.ToString, Title, " " + imm.ID.ToString + " <br/> " + " " + imm.PREZZO.ToString + "<br/>")
'Aggiungo gli eventi onmouseover e onmouseout
'onmouseover: stm(Text[row_della_array],Style[row_style_definito_nel_file_js] (main15.js)
'onmouseout: chiama htm(); che serve solo per cancellare la popup (che e' un <div> nascosto).
e.Row.Attributes.Add("onmouseover", "stm(Text[" + e.Row.DataItemIndex.ToString + "], Style[5]);")
e.Row.Attributes.Add("onmouseout", "htm();")
' Se vuoi aggiungere solo a una o diverse celle attributi come sopra userai questa forma.
''e.Row.Cells(0).Attributes.Add("onmouseover", "stm(Text[" + e.Row.DataItemIndex.ToString + "], Style[5]);")
''e.Row.Cells(0).Attributes.Add("onmouseout", "htm();")
''e.Row.Cells(0) Prima cella , e.Row.Cells(1) seconda ......... ecc.
End If
End If
End Sub
Private Function addTextTips(ByVal RowId As Integer, ByVal Titolo As String, ByVal Descrizione As String) As String
Return "Text[" + RowId.ToString + "]=[" + "'" + Titolo + "'," + "'" + Descrizione + "'];" + vbCrLf
End Function