Bonjour,
Comment récupérer l'évenement Click dans un DataGrid ?
Par exemple : L'utilisteur click sur une case d'un Datagrid et je récupère toutes les infos de la ligne.
Il n'existe pas d'envemenent OnClick alors je ne vois pas trop comment faire...
Version imprimable
Bonjour,
Comment récupérer l'évenement Click dans un DataGrid ?
Par exemple : L'utilisteur click sur une case d'un Datagrid et je récupère toutes les infos de la ligne.
Il n'existe pas d'envemenent OnClick alors je ne vois pas trop comment faire...
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21Public Sub dg_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg.ItemDataBound Dim strCommclick As String Dim strCommSurvol As String Dim strParamUrl As String strParamUrl = HttpUtility.UrlEncode(e.Item.Cells(Session("indexLogin")).Text) 'Gestion du lien vers la fiche If Not e.Item.ItemIndex = -1 Then strCommclick = "window.location.href='utilisatFicheNew.aspx?login=" & strParamUrl & "'" e.Item.Attributes.Add("onClick", strCommclick) End If 'Gestion de la couleur lors du passage de la souris If Not e.Item.ItemIndex = -1 Then If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#C4EEF9'; this.style.cursor='pointer'") e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#b0e0e6'") End If End If End Sub
Merci beaucoup pour ce code, je n'y avais pas pensé et c'est très efficace.
Voici la traduction en c# :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 public void dg_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { string strCommclick; string strCommSurvol; string strParamUrl; strParamUrl = HttpUtility.UrlEncode(e.Item.Cells(Session("indexLogin")).Text); if (!(e.Item.ItemIndex == -1)) { strCommclick = "window.location.href='utilisatFicheNew.aspx?login=" + strParamUrl + "'"; e.Item.Attributes.Add("onClick", strCommclick); } if (!(e.Item.ItemIndex == -1)) { if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem) { e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#C4EEF9'; this.style.cursor='pointer'"); e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#b0e0e6'"); } } }