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 :

[C#/ASP.NET] Gridview imbriqués avec utilisation d'un UserControl


Sujet :

ASP.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé Avatar de Vinceee38
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    134
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 134
    Par défaut [C#/ASP.NET] Gridview imbriqués avec utilisation d'un UserControl
    Bonjour tout le monde,

    Présentation du besoin :

    J'essaye de créer un gridview à plusieurs niveaux (qui contient un autre GridView). J'ai un premier Gridview dans ma page principale contenu dans un UpdatePanel. Dans ce gridview pour chaque ligne j'ai un bouton qui permet d'afficher un UserControl. La subtilité est que ce UserControl comporte aussi un GridView.

    Problème rencontré :

    J'ai mi en place les fonctionnalités pour pouvoir Editer ma première GridView, jusqu’à la aucun problème.
    Aujourd'hui je cherche à mettre en place l'edition des données pour le deuxième GridView contenu dans mon UserControl donc j'ai fait exactement la meme chose que pour le premier mais quand je clique sur EDIT le UserControl disparait. De plus l'événement OnRowEditing n'est même pas appelé.


    Mon Code :

    Parks.aspx :
    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
     
            <asp:UpdatePanel ID="udpGrid" runat="server">
                <ContentTemplate>
                    <asp:GridView ID="gvParks" runat="server" DataSourceID="R2P_gridview" 
                        AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" 
                        CellPadding="4" ForeColor="#333333" GridLines="None" 
                        OnRowCommand="GvParks_RowCommand" OnRowEditing="GvParks_OnRowEditing" 
                        onrowupdated="GvParks_RowUpdated" onrowupdating="gvParks_RowUpdating">
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                        <Columns>
                            <asp:TemplateField>
                                <ItemTemplate>
                                   <asp:Button ID="btnShow" runat="server" Text="Show Attractions" CommandName="show" CommandArgument='<%# Container.DataItemIndex %>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Id" Visible="false">
                            <ItemTemplate>
                             <asp:Label ID="lblID" runat="server" Text='<%# Eval("pre_id") %>'></asp:Label>
                            </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Park Name" SortExpression="pre_libelle">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtLibelle" runat="server" Text='<%# Bind("pre_libelle") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lbllibelle" runat="server" Text='<%# Bind("pre_libelle") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField  DataField="zone_libelle" HeaderText="Country" SortExpression="zone_libelle" />
                            <asp:BoundField  DataField="zone_CP" HeaderText="Zip Code" SortExpression="zone_CP" />
                            <asp:BoundField  DataField="zone_longitude" HeaderText="Longitude" SortExpression="zone_longitude" />
                            <asp:BoundField  DataField="zone_latitude" HeaderText="Latitude" SortExpression="zone_latitude" />
                            <asp:BoundField  DataField="zone_zoom" HeaderText="Zoom" SortExpression="zone_zoom" />
                            <asp:CommandField EditImageUrl="~/Ressources/img/admin/Edit.png"  UpdateImageUrl="~/Ressources/img/admin/Valide.png"  CancelImageUrl="~/Ressources/img/admin/Cancel.png" ShowEditButton="True" ButtonType="Image" HeaderStyle-HorizontalAlign= "Center"/>
                            <asp:TemplateField>
                            <ItemTemplate>
                                <tr>
                                    <td colspan="2"></td>
                                    <td colspan="8"><asp:Panel ID="pnlAttractions" runat="server"></asp:Panel></td>
                                </tr>
                            </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <EditRowStyle BackColor="#999999" />
                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <SortedAscendingCellStyle BackColor="#E9E7E2" />
                        <SortedAscendingHeaderStyle BackColor="#506C8C" />
                        <SortedDescendingCellStyle BackColor="#FFFDF8" />
                        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                    </asp:GridView>
                </ContentTemplate>
            </asp:UpdatePanel>
        <br /> <br /> <br /> <br />
     
        <asp:SqlDataSource ID="R2P_gridview" runat="server" 
            ConnectionString="<%$ ConnectionStrings:r2pConnectionString %>" 
            ProviderName="<%$ ConnectionStrings:r2pConnectionString.ProviderName %>" 
            SelectCommand="SELECT pre_id, pre_libelle, zone_libelle, zone_CP, zone_longitude, zone_latitude, zone_zoom FROM r2p_vue_prestation_park">
        </asp:SqlDataSource>
    Parks.aspx.cs :

    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
     
            private static UCAttractions ucAttraction = new UCAttractions();
     
            protected void Page_Load(object sender, EventArgs e)
            {
            }
     
            protected void GvParks_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                if (e.CommandName == "show")
                {
                    int RowIndex = Convert.ToInt32((e.CommandArgument).ToString());
                    Button btn = (Button)gvParks.Rows[RowIndex].FindControl("btnShow");
                    Panel p = (Panel)gvParks.Rows[RowIndex].FindControl("pnlAttractions");
     
                    if (btn.Text == "Show Attractions")
                    {
                        Int32 pre_id = Int32.Parse(((Label)gvParks.Rows[RowIndex].FindControl("lblID")).Text);
                        UCAttractions ucAttraction = SetUCAttraction(pre_id);
                        p.Controls.Add(ucAttraction);
                        p.Visible = true;
                        btn.Text = "Hide Attractions";
                    }
                    else if (btn.Text == "Hide Attractions")
                    {
                        p.Visible = false;
                        btn.Text = "Show Attractions";
                    }
     
                }
            }
     
            private UCAttractions SetUCAttraction(Int32 Id)
            {
                ucAttraction = (UCAttractions)Page.LoadControl("~/Admin/UserControl/UCAttractions.ascx");
                ucAttraction.DataSource = Id;
                return ucAttraction;
            }
     
            protected void GvParks_OnRowEditing(object sender, GridViewEditEventArgs e)
            {
                gvParks.EditIndex = e.NewEditIndex;
                gvParks.DataBind();
     
            }
     
            protected void gvParks_RowUpdating(object sender, GridViewUpdateEventArgs e)
            {
                // get the information
                int rowIndex = e.RowIndex;
                GridViewRow row = gvParks.Rows[rowIndex];
                String categoryID = ((TextBox)row.FindControl("txtLibelle")).Text;
                gvParks.EditIndex = -1;
                gvParks.DataBind();
                e.Cancel = true;
                gvParks.Rows[rowIndex].BackColor = System.Drawing.Color.LightGreen;
            }
     
            protected void GvParks_RowUpdated(object sender, GridViewUpdatedEventArgs e)
            {
               //TODO
            }
    Mon UserControl UCAttractions.ascx:

    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
     
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UCAttractions.ascx.cs" Inherits="R2PWeb.Admin.UserControl.UCAttractions" %>
            <asp:GridView ID="GvAttractions" runat="server" 
                DataSourceID="dsR2P_gvAttraction"
                AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="None"
                OnRowEditing="GvAttractions_OnRowEditing">
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <Columns>
                    <asp:BoundField DataField="pre_libelle" HeaderText="Attraction Name" SortExpression="pre_libelle" Visible="true"/>
                    <asp:ImageField DataImageUrlField="med_url" HeaderText="Attraction picture"></asp:ImageField>
                    <asp:BoundField  DataField="pre_id" HeaderText="pre_id" SortExpression="pre_id" Visible="false"/>
                    <%--<asp:HyperLinkField DataNavigateUrlFields="pre_id" Text="<img src='../Ressources/img/admin/edit.png' border='0' />"  HeaderText="Edit" DataNavigateUrlFormatString="~/Admin/EditAttraction.aspx?Id={0}" DataTextFormatString="Edit record {0}"/>--%>
                    <asp:CommandField EditImageUrl="~/Ressources/img/admin/Edit.png"  UpdateImageUrl="~/Ressources/img/admin/Valide.png"  CancelImageUrl="~/Ressources/img/admin/Cancel.png" ShowEditButton="True" ButtonType="Image" HeaderStyle-HorizontalAlign= "Center" CausesValidation="false"/>
                </Columns>
                <EmptyDataTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text="Pas de parcs" Width="100%" />
                </EmptyDataTemplate>
                <EditRowStyle BackColor="#999999" />
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#E9E7E2" />
                <SortedAscendingHeaderStyle BackColor="#506C8C" />
                <SortedDescendingCellStyle BackColor="#FFFDF8" />
                <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
            </asp:GridView>
    <asp:SqlDataSource ID="dsR2P_gvAttraction" SelectCommand = "SELECT pre_libelle, med_url, pre_id FROM r2p_vue_attraction_mini where pre_parent_id = @pre_id" runat="server"  ConnectionString="<%$ ConnectionStrings:r2pConnectionString %>" ProviderName="<%$ ConnectionStrings:r2pConnectionString.ProviderName %>" >
    </asp:SqlDataSource>

    UCAttractions.ascx.cs :

    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
     
            private Int32 _data = -1;
     
            public Int32 DataSource
            {
                get { return _data; }
                set
                {
                    _data = value;
                    DataChange(value);
                }
            }
            private void DataChange(Int32 value)
            {
                dsR2P_gvAttraction.SelectCommand = "SELECT pre_libelle, med_url, pre_id FROM r2p_vue_attraction_mini where pre_parent_id = " + _data;
                dsR2P_gvAttraction.DataBind();
                GvAttractions.DataBind();
            }
     
            protected void Page_Load(object sender, EventArgs e)
            {
                if (_data != -1)
                {
                    String test = dsR2P_gvAttraction.SelectCommand;
                    dsR2P_gvAttraction.SelectParameters.Add("pre_id", _data.ToString());
                    test = dsR2P_gvAttraction.SelectCommand;
                }
            }
     
            protected void GvAttractions_OnRowEditing(object sender, GridViewEditEventArgs e)
            {
     
            }
    J'ai déjà beaucoup cherché sur Internet mais sans succès c'est pour cela que je me tourne vers vous.

    Merci d'avance à tout ceux qui essayeront de m'aider !

  2. #2
    Membre confirmé Avatar de Vinceee38
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    134
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 134
    Par défaut
    Bon finalement j'ai utilisé ce tuto :

    http://www.ashishblog.com/blog/neste...t-using-c-net/

    J'ai tout mi sur la même page... Tant pis pour les UC.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 5
    Dernier message: 19/07/2012, 13h46
  2. Réponses: 8
    Dernier message: 28/05/2009, 10h40
  3. [CR][ASP.Net] Incohérence PageNumber avec/sans condition
    Par SoaB dans le forum SAP Crystal Reports
    Réponses: 1
    Dernier message: 13/01/2006, 12h10
  4. enregistrer asp.net 1.1 avec IIS
    Par argv666 dans le forum ASP
    Réponses: 2
    Dernier message: 11/04/2005, 16h31
  5. [CR][ASP.NET] Un champ avec plusieurs polices...
    Par David.V dans le forum SAP Crystal Reports
    Réponses: 2
    Dernier message: 08/04/2004, 14h19

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