IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

TemplateField avec action particulière


Sujet :

ASP.NET

  1. #1
    Membre expérimenté
    Avatar de zooffy
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Août 2004
    Messages
    3 895
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : Bâtiment

    Informations forums :
    Inscription : Août 2004
    Messages : 3 895
    Par défaut TemplateField avec action particulière
    Salut

    Suite à la panne du serveru, mon topic a sauté, donc je le relance, mais vu que je me rappelle plus où on en était, je repars de mon avancée actuelle.
    @Calagan99 : remets ton idée, j'ai vu ton alerte, mais j'ai pas vu ton message.

    Donc, j'ai mis un GridView dans un UpdatePanel. Ma page définitive est assez complexe car je doit faire pas mal de chose avec plein de bouton du GridView. Je joue avec des affichage/Masquage de <asp:Table pour gérer chaque "fonction".
    Mais là, ce qui m'occupe est une fonction assez simple (enfin dans le principe). Mon GridView affiche des campagnes publicitaires. L'idée est d'avoir un bouton qui montre son état (Actif/Inactif) et qui permet de changer l'état en cliquant dessus. j'ai pris l'option d'un TempalteField (le bouton d'à côté ouvre une Popup pour faire une apreçus et ça marche)

    Donc j'ai incriminer d'autres morceau de code de ma page finale et j'ai retirer bout par bout des fonctions de la apge. Mais maintenant, je ne peux plus rien retirer et ça marche toujours pas.

    Le symptome est simple : il ne passe pas dans la Sub que j'a rajouter avec un AddHandler sur le bouton du TemplateField.

    Je vous livre mon code en entier. Si vous pouvez me trouver ce qui déconne ou m'aider à chercher car là, je sèche.

    Merci d'avance.

    Côté HTML :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
     
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
    <title>Page sans titre</title>
    <script type="text/javascript" src="Scripts/Global.js"></script>
    <script type="text/javascript">
    function test(aff) {
    	alert('un truc qui dit qu on est dans la fonction JS + la variable qu on reçoit : ' + aff);
    }
    </script>
     
    </head>
    <body>
    <form id="form1" runat="server">
    <ajax:ScriptManager ID="smTest" runat="server"></ajax:ScriptManager>
    <asp:SqlDataSource ID="sdsGvCampagne" runat="server" 
    	DataSourceMode="DataSet"
    	ConnectionString="<%$ ConnectionStrings:CS %>">
    </asp:SqlDataSource>
     
    <ajax:UpdatePanel ID="upCampagne" runat="server" UpdateMode="Always" RenderMode="Inline">
    	<Triggers>
     
    	</Triggers>
    	<ContentTemplate>
    	<asp:GridView ID="gvCampagne" runat="server" Width="100%"
    		DataSourceID="sdsGvCampagne"
    		AutoGenerateColumns="false" 
    		AllowPaging="true" 
    		AllowSorting="true"
    		DataKeyNames="Id_Campagne" 
    		PageSize="15" 
    		PagerStyle-HorizontalAlign="Center">
    		<PagerSettings Position="Bottom" 
    			Mode="Numeric" 
    			FirstPageText="Début" 
    			LastPageText="Fin" 
    			NextPageText="Suivant" 
    			PreviousPageText="Précédent" />
    		</asp:GridView>
    		<asp:PlaceHolder ID="FormuModif" runat="server"></asp:PlaceHolder>
    	</ContentTemplate>
    </ajax:UpdatePanel>
    </form>
    </body>
    </html>
    Côté CodeBehind
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
     
    Partial Class test
    	Inherits System.Web.UI.Page
     
    	Private dmCS As New DataManager("CS")
     
    	Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    		ChargeSDS()
    	End Sub
     
    	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    		ConstruireGV()
    		AfficheTable("rien")
    	End Sub
     
    	Protected Sub gvCampagne_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvCampagne.PageIndexChanged
    		ChargeSDS()
    	End Sub
     
    	Protected Sub gvCampagne_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvCampagne.RowCommand
     
    		Dim IdCell As TableCell
    		If IsNumeric(e.CommandArgument) Then
    			IdCell = CType(gvCampagne.Rows(Convert.ToInt32(e.CommandArgument)), GridViewRow).Cells(0)
    		Else
    			IdCell = gvCampagne.Rows(0).Cells(0)
    			AfficheTable("rien")
    		End If
    		Select Case e.CommandName
    			Case "first", "next", "last", "prev"
    				AfficheTable("rien")
    				ChargeSDS()
     
    			Case "Actif"
    				dmCS.ExecuterRequeteSimple("EXEC SPEC_Campagne_Actif " & IdCell.Text)
    		End Select
    	End Sub
     
     
    	Sub AfficheTable(ByVal tab As String)
    		If tab <> "rien" Then
    			CType(FormuModif.FindControl(tab), Table).Visible = True
    		End If
    	End Sub
     
    	Sub ConstruireGV()
    		Dim idcampagne, libelle, objet, regie, boolactif As New BoundField
    		With idcampagne
    			.HeaderText = "ID"
    			.DataField = "Id_Campagne"
    		End With
    		With libelle
    			.HeaderText = "Libellé"
    			.DataField = "Libelle"
    			.SortExpression = "Libelle"
    		End With
    		With objet
    			.HeaderText = "Objet"
    			.DataField = "Objet"
    			.SortExpression = "Objet"
    		End With
    		With regie
    			.HeaderText = "Régie"
    			.DataField = "Regie"
    			.SortExpression = "Regie"
    		End With
     
    		Dim apercu, actif As New TemplateField
    		With apercu
    			.ItemTemplate = New TemplatePopup(DataControlRowType.DataRow, "Id_Campagne", "Apercu")
    			.HeaderTemplate = New TemplatePopup(DataControlRowType.Header, "Aperçu", "Apercu")
    		End With
    		With actif
    			.ItemTemplate = New TemplatePopup(DataControlRowType.DataRow, "Actif", "Actif")
    			.HeaderTemplate = New TemplatePopup(DataControlRowType.Header, "Actif", "Actif")
    		End With
     
    		Dim test, envoi, segment, modif As New ButtonField
    		With test
    			.HeaderText = "Test"
    			.ButtonType = ButtonType.Image
    			.ImageUrl = "~/App_Themes/" & GetNomsite() & "/lettresinfo.png"
    			.CommandName = "Test"
    		End With
    		With envoi
    			.HeaderText = "Envoi"
    			.ButtonType = ButtonType.Image
    			.ImageUrl = "~/App_Themes/" & GetNomsite() & "/lettresinfo.png"
    			.CommandName = "Envoi"
    		End With
    		With segment
    			.HeaderText = "@"
    			.ButtonType = ButtonType.Image
    			.ImageUrl = "~/App_Themes/" & GetNomsite() & "/lettresinfo.png"
    			.CommandName = "Segment"
    		End With
    		With modif
    			.HeaderText = "Modif"
    			.ButtonType = ButtonType.Image
    			.ImageUrl = "~/App_Themes/" & GetNomsite() & "/modifier_16.png"
    			.CommandName = "Modif"
    		End With
     
    		Dim StatutEnvoi As New ImageField
    		With StatutEnvoi
    			.HeaderText = "Envoi"
    			.DataImageUrlField = "Envoi"
    			.DataImageUrlFormatString = "~/App_Themes/" & GetNomsite() & "/{0}.png"
    		End With
     
    		With gvCampagne
    			With .Columns
    				.Clear()
    				.Add(idcampagne)
    				.Add(libelle)
    				.Add(objet)
    				.Add(regie)
    				.Add(apercu)
    				'.Add(test)
    				'.Add(envoi)
    				'.Add(StatutEnvoi)
    				.Add(actif)
    				'.Add(modif)
    			End With
    			.DataSourceID = "sdsGvCampagne"
    		End With
    	End Sub
     
    	Sub ChargeSDS()
    		sdsGvCampagne.SelectCommand = "EXEC dbo.SPEC_ListeCampagne '" & GetApplicationGUID().ToString & "', '00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-000000000000', 'deux', '', 0"
    	End Sub
     
    	Protected Sub gvCampagne_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvCampagne.RowDataBound
    		If e.Row.RowType = DataControlRowType.DataRow Then
    			If e.Row.RowType = DataControlRowType.DataRow Then
    				Dim lnk As HyperLink = CType(e.Row.FindControl("hlCamp" & CType(DataBinder.Eval(e.Row, "DataItem.Id_Campagne"), String)), HyperLink)
    				With lnk
    					.NavigateUrl = String.Format("JavaScript:test(' ceci vient du code : {0}');", CType(DataBinder.Eval(e.Row, "DataItem.Id_Campagne"), String))
    					.ImageUrl = "~/App_Themes/" & GetNomsite() & "/lettresinfo.png"
    				End With
    				Dim ibactif As ImageButton = CType(e.Row.FindControl("ibActif" & CType(DataBinder.Eval(e.Row, "DataItem.Id_Campagne"), String)), ImageButton)
    				With ibactif
    					AddHandler ibactif.Click, AddressOf actifCampagne
    					.ImageUrl = "~/App_Themes/" & GetNomsite() & "/" & CType(DataBinder.Eval(e.Row, "DataItem.Actif"), String) & ".png"
    					.CommandArgument = CType(DataBinder.Eval(e.Row, "DataItem.Id_Campagne"), String)
    				End With
    			End If
    		End If
    	End Sub
     
    	Sub actifCampagne(ByVal sender As Object, ByVal e As ImageClickEventArgs)
    		Dim ib As ImageButton = sender
    		Dim dt As DataTable = New DataManager("CS").ExecuterRequeteSimple("EXEC SPEC_ActifCampagne " & ib.CommandArgument)
    		LogageOW("je passe dans le actifCampagne avec le : " & ib.CommandArgument)
    		ConstruireGV()
    	End Sub
    End Class
     
    Public Class TemplatePopup
    	Implements ITemplate
     
    	Private templateType As DataControlRowType
    	Private columnName As String
    	Private controleName As String
     
    	Sub New(ByVal type As DataControlRowType, ByVal colname As String, ByVal ctrlName As String)
    		templateType = type
    		columnName = colname
    		controleName = ctrlName
    	End Sub
     
    	Sub InstantiateIn(ByVal container As System.Web.UI.Control) _
    	 Implements ITemplate.InstantiateIn
     
    		Select Case templateType
    			Case DataControlRowType.Header
    				Dim lc As New Literal
    				lc.Text = "<b>" & columnName & "</b>"
    				container.Controls.Add(lc)
     
    			Case DataControlRowType.DataRow
    				Select Case controleName
    					Case "Apercu"
    						Dim hl As New HyperLink
    						AddHandler hl.DataBinding, AddressOf hl_DataBinding
    						container.Controls.Add(hl)
    					Case "Actif"
    						Dim ib As New ImageButton
    						AddHandler ib.DataBinding, AddressOf ib_DataBinding
    						container.Controls.Add(ib)
    					Case Else
     
    				End Select
     
    			Case Else
    				' Insert code to handle unexpected values. 
    		End Select
    	End Sub
     
    	Private Sub hl_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
    		Dim l As HyperLink = CType(sender, HyperLink)
    		Dim row As GridViewRow = CType(l.NamingContainer, GridViewRow)
    		l.Text = DataBinder.Eval(row.DataItem, "Id_Campagne").ToString()
    		l.ID = "hlCamp" & DataBinder.Eval(row.DataItem, "Id_Campagne").ToString()
    	End Sub
     
    	Private Sub ib_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
    		Dim l As ImageButton = CType(sender, ImageButton)
    		Dim row As GridViewRow = CType(l.NamingContainer, GridViewRow)
    		l.ID = "ibActif" & DataBinder.Eval(row.DataItem, "Id_Campagne").ToString()
    	End Sub
    End Class

  2. #2
    Modérateur

    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2007
    Messages
    1 996
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2007
    Messages : 1 996
    Par défaut
    Zooffy,

    hier je te proposais si je me souviens bien de modifier ton HyperLink en LinkButton.

    L'intérêt étant de passer un commandName à ce linkbutton (ex : CommandName="select").

    De cette manière, tu interceptes le clic sur le linkbutton dans l'événement ItemCommand de ta gridview.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Protected sub gridview1_itemCommand ... Handles...
    Select case e.commandName
        case "select"
            le code de ton AddHandler
    end select
    end sub

  3. #3
    Membre expérimenté
    Avatar de zooffy
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Août 2004
    Messages
    3 895
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : Bâtiment

    Informations forums :
    Inscription : Août 2004
    Messages : 3 895
    Par défaut
    Merci pour ton aide.

    Sauf que, c'est pas l'hyperLink qui me pose un soucis, mais le ImageBouton.

    L'hyperLink fonctionne trés bien, et justement, vu que je lance un Jscript dessus, je ne pouvais pas metre autre chose.

    Une autre idée peut être ?

  4. #4
    Modérateur

    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2007
    Messages
    1 996
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2007
    Messages : 1 996
    Par défaut
    je me suis trompé, je voulais parler de l'imageButton et pas du HyperLink.

    Tu peux faire de même avec le linkbutton, en lui affectant une image d'arriere plan en css.

  5. #5
    Membre expérimenté
    Avatar de zooffy
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Août 2004
    Messages
    3 895
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : Bâtiment

    Informations forums :
    Inscription : Août 2004
    Messages : 3 895
    Par défaut
    Ok, je vais essayer un truc du genre. Je pourrais pas lui scotcher une iamge d'arrière plan car l'image dépend de la valeur du champ Actif.

    Donc, faut que je vois comment lui mettre une iamge en fonction d'une condition.

    Je tente ça et je reviens te tenir au courant.

  6. #6
    Membre expérimenté
    Avatar de zooffy
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Août 2004
    Messages
    3 895
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : Bâtiment

    Informations forums :
    Inscription : Août 2004
    Messages : 3 895
    Par défaut
    Bon, j'ai modifié le truc en mettn un LinkButton à la place de l'ImageButton.

    J'ai ajouté un CommandeName dans la RowDataBound et j'ai placé une entrée de code dans le RowComamnd du GriView (le itemCommande n'éxiste pas dans le GridVeiw)

    Et bien sûr, j'ai enlevé le AddHandler.

    Bilan : toujours pareil, ça marche pas. Il passe pas dans la RowCommande.

    Une autre idée ?

  7. #7
    Membre expérimenté
    Avatar de zooffy
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Août 2004
    Messages
    3 895
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : Bâtiment

    Informations forums :
    Inscription : Août 2004
    Messages : 3 895
    Par défaut
    Je viens de modifier l'ensmble de la apge pour le metre sur ma bécane et pouvoir utiliser le débogueur.

    J'ai mis un point d'arrêt à la fin du DataRowBound, sur le dernier End If et j'ai réduit ma requête à une ligne, histoire de pas tout me taper.

    Ce que je constate :
    - il passe trois fois (au moins) dans le DataRowBound, ce que je ne comprends pas bien, puisqu'il n'y a qu'une ligne.
    - au dernier passage, le test du
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    If e.Row.RowType = DataControlRowType.DataRow Then
    est faux, donc le dernier passage est à vide.
    - ensuite il sort par le End Sub et pouf, plus rien, il affiche la page.
    A aucun moment il ne passe par le RowCommand. Mais il doit forcément passer par un endroit avant d'afficher la page en sortant du DataRowBound, sauf que je vois pas.

    Là, j'ai vraiment besoins d'un coup de main.

Discussions similaires

  1. Réponses: 3
    Dernier message: 27/04/2009, 17h55
  2. créer bouton "other" avec action particulière
    Par dida.ratsimba dans le forum W4 Express
    Réponses: 4
    Dernier message: 17/11/2008, 15h58
  3. Débutante - Code VBA pour MsgBox avec actions multiples
    Par kisscool35 dans le forum Access
    Réponses: 5
    Dernier message: 22/08/2006, 17h43
  4. Réponses: 1
    Dernier message: 22/08/2006, 13h45
  5. Appeler une fonction avec "action" ds un
    Par drinkmilk dans le forum ASP
    Réponses: 4
    Dernier message: 20/04/2004, 14h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo