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 :
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
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>
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
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 }
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 :
J'ai d�j� beaucoup cherch� sur Internet mais sans succ�s c'est pour cela que je me tourne vers vous.
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) { }
Merci d'avance � tout ceux qui essayeront de m'aider !
Partager