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 :

Probleme avec un modalpopup


Sujet :

ASP.NET

  1. #1
    Membre éprouvé
    Inscrit en
    Août 2008
    Messages
    1 596
    Détails du profil
    Informations forums :
    Inscription : Août 2008
    Messages : 1 596
    Par défaut Probleme avec un modalpopup
    Bonjour, j'ai pu créer mon gridview et mon madalpopup sauf que ce dernier s'affiche sue le premier clique sinon il me dit '$common a la valeur null ou n'est pas un objet'
    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
     
     <form id="form1" runat="server">
     
             <!--=============================================================================================================================================================================-->
            <asp:ScriptManager ID="ScriptManager1" runat="server"/>
     
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    SelectCommand="SELECT [idCategorie], [Categorie] FROM [Categorie]"
                    SelectCommandType="Text" ConnectionString="<%$ ConnectionStrings:ASSURANCEConnectionString %>" />
                <asp:SqlDataSource ID="SqlDataSourceDetail" runat="server" 
                    SelectCommand="SELECT [idCategorie], [Categorie] FROM [Categorie]where idCategorie=@idCategorie"
                    SelectCommandType="Text" CancelSelectOnNullParameter="true" ConnectionString="<%$ ConnectionStrings:ASSURANCEConnectionString %>"/>
     
                <asp:SqlDataSource id="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ASSURANCEConnectionString %>" SelectCommand="SELECT [idCategorie], [Categorie] FROM [Categorie]"></asp:SqlDataSource> 
     
                   <asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>            
                        <asp:Label ID="lblTitle" runat="server" Text="Catégories" BackColor="lightblue" Width="50%" />
                        <asp:GridView 
                            ID="gvCategorie" runat="server" DataKeyNames="idCategorie" AutoGenerateColumns="false" 
                            AllowPaging="true" AllowSorting="true" PageSize="10" DataSourceID="SqlDataSource1" Width="50%">
                            <AlternatingRowStyle BackColor="aliceBlue" />
                            <HeaderStyle HorizontalAlign="Left" />
                            <Columns>
    					        <asp:TemplateField>
    						        <ItemTemplate>
    							            <asp:ImageButton ID="btnEdit" runat="server"  OnClick="btnEditCategorie_Click" ImageUrl="~/images/btn_edit.gif"/>
    						        </ItemTemplate>
    					        </asp:TemplateField>
    					        <asp:BoundField DataField="idCategorie" HeaderText="ID" ReadOnly="True" SortExpression="idCategorie"></asp:BoundField>
                                <asp:BoundField DataField="Categorie" HeaderText="Categorie" SortExpression="Categorie"></asp:BoundField>
     
    					        </Columns>					
                        </asp:GridView>
                    </ContentTemplate>
                </asp:UpdatePanel>          
     
                <asp:Button id="btnShowPopup" runat="server" style="display:none" />
            <br />
            <br />
            <br />
    			<asp:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlPopup" CancelControlID="btnClose" BackgroundCssClass="modalBackground" />
     
    			<asp:Panel ID="pnlPopup" runat="server" Width="500px" style="display:none">
                    <asp:UpdatePanel ID="updPnlCategorieDetail" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <asp:Label ID="lblCategorieDetail" runat="server" Text="Détail catégorie" BackColor="lightblue" Width="95%" />
                            <asp:DetailsView ID="dvCategorieDetail" runat="server" DefaultMode="Edit" Width="95%" BackColor="white" />
                        </ContentTemplate>                
                    </asp:UpdatePanel>
                    <div  style="width:95%">
                        <asp:Button ID="btnSave" runat="server" Text="Save" 
                            OnClientClick="alert('Sorry, but I didnt implement save because I dont want my northwind database getting messed up.'); return false;" 
                            Width="50px" />
                        <asp:Button ID="btnClose" runat="server" Text="Close" Width="50px" />
                    </div>             
                </asp:Panel>
     
                <!--=============================================================================================================================================================================-->
     
        </form>
    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
    protected void btnEditCategorie_Click(object sender, EventArgs e)
        {
            //  get the gridviewrow from the sender so we can get the datakey we need
            ImageButton btnDetails = sender as ImageButton;
            GridViewRow row = (GridViewRow)btnDetails.NamingContainer;
     
            //  extract the categorieid from the row whose details button originated the postback.
            //  grab the categorieid and feed it to the categorie details datasource
            //  finally, rebind the detailview
            this.SqlDataSourceDetail.SelectParameters.Clear();
            this.SqlDataSourceDetail.SelectParameters.Add("idCategorie", Convert.ToString(this.gvCategorie.DataKeys[row.RowIndex].Value));
            this.dvCategorieDetail.DataSource = this.SqlDataSourceDetail;
            this.dvCategorieDetail.DataBind();
     
            //  update the contents in the detail panel
            this.updPnlCategorieDetail.Update();
            //  show the modal popup
            this.mdlPopup.Show();
     
        }

  2. #2
    Membre éprouvé
    Inscrit en
    Août 2008
    Messages
    1 596
    Détails du profil
    Informations forums :
    Inscription : Août 2008
    Messages : 1 596
    Par défaut
    le champs fieldhidden garde toujours la valeur du premier clique et le modal popup de l'index 1 ne veut pas s'ouvrir a nouveau lorsque je clique sur "cancel"

  3. #3
    Membre éprouvé
    Inscrit en
    Août 2008
    Messages
    1 596
    Détails du profil
    Informations forums :
    Inscription : Août 2008
    Messages : 1 596
    Par défaut
    j'ai suivi l'exemple suivant mais ca n'a pas marché
    http://www.codeproject.com/KB/webfor...pupExtend.aspx

    j'ai essayé un deuxieme exemple et ca n'a pas marché aussi, il y a quelque chose qui m'echape.

    http://mattberseth.com/blog/2008/04/..._gridview.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
    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
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
     
    <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        Namespace="System.Web.UI" TagPrefix="asp" %>
     
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
     
    <!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 runat="server">
        <title>Gestion d'assurance</title>
            <link type="text/css" href="datagrid.css" rel="stylesheet" />  
        <link type="text/css" href="detailgrid.css" rel="stylesheet" /> 
     
    </head>
    <body>
        <form id="form1" runat="server">
     
             <!--=============================================================================================================================================================================-->
            <asp:ScriptManager ID="ScriptManager1" runat="server"/>
     
                <script type="text/javascript" language="javascript">
                //  attach to the pageLoaded event
                Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);        
     
                function pageLoaded(sender, args) {
     
                    //  the data key is the control's ID
                    var dataKey = '<%= this.gvCustomers.ClientID %>';
                    var updatedRowIndex = args.get_dataItems()[dataKey];
     
                    //  if there is a datakey for the grid, use it to
                    //  identify the row that was updated
                    if(updatedRowIndex){
                        //  get the row that was updated
                        var tr = $get(dataKey).rows[parseInt(updatedRowIndex) + 1];
                        //  add the 'updated' css class
                        Sys.UI.DomElement.addCssClass(tr, 'updated');
     
                        //  remove the css class in 1.5 seconds
                        window.setTimeout(function(){
                            Sys.UI.DomElement.removeCssClass(
                                tr,
                                'updated'
                            );                        
                        }, 1500);
                    }
                }
            </script> 
     
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    SelectCommand="SELECT [idCategorie], [Categorie] FROM [Categorie]"
                    SelectCommandType="Text" ConnectionString="<%$ ConnectionStrings:ASSURANCEConnectionString %>" />
                <asp:SqlDataSource ID="SqlDataSourceDetail" runat="server" 
                    SelectCommand="SELECT [idCategorie], [Categorie] FROM [Categorie] where idCategorie=@idCategorie"
                    SelectCommandType="Text" CancelSelectOnNullParameter="true" ConnectionString="<%$ ConnectionStrings:ASSURANCEConnectionString %>">
                <SelectParameters>
                    <asp:Parameter Name="idCategorie" Type="Int32" />
                </SelectParameters>
                </asp:SqlDataSource>
     
     
            <asp:UpdatePanel ID="updatePanel1" runat="server" UpdateMode="Conditional">
                <ContentTemplate>            
                    <asp:GridView ID="gvCustomers" runat="server" DataSourceID="SqlDataSource1"
                        CssClass="datagrid" GridLines="None" AutoGenerateColumns="false"
                        OnSelectedIndexChanged="GvCustomers_SelectedIndexChanged" DataKeyNames="idCategorie">
                        <Columns>
    				        <asp:BoundField DataField="idCategorie" HeaderText="ID" ReadOnly="true" />
    				        <asp:BoundField DataField="Categorie" HeaderText="Categorie" ReadOnly="true" />    
    				        <asp:TemplateField>
    					        <ItemTemplate>
    					            <asp:LinkButton ID="btnViewDetails" runat="server" Text="Edit" CommandName="Select" />
    					        </ItemTemplate>
    				        </asp:TemplateField>				        
                        </Columns>					
                    </asp:GridView>
                </ContentTemplate>
            </asp:UpdatePanel> 
     
     
            <asp:Panel ID="Panel1" runat="server" CssClass="detail" Width="500px" style="display:none;">
                <asp:UpdatePanel ID="updPnlCustomerDetail" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <asp:Button id="btnShowPopup" runat="server" style="display:none" />
                		<asp:ModalPopupExtender ID="mdlPopup" runat="server" 
                		    TargetControlID="btnShowPopup" PopupControlID="pnlPopup" 
                		    CancelControlID="btnClose" BackgroundCssClass="modalBackground" 
                		/>
                        <asp:DetailsView ID="dvCustomerDetail" runat="server" DataSourceID="SqlDataSourceDetail" 
                            CssClass="detailgrid" GridLines="None" DefaultMode="Edit" AutoGenerateRows="false" 
                            Visible="false" Width="100%">
                            <Fields>
                                <asp:BoundField HeaderText="ID" DataField="idCategorie" ReadOnly="true" />
                                <asp:TemplateField HeaderText="Categorie">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="txtCategorie" runat="server" Text='<%# Bind("Categorie") %>' />
                                        <asp:RequiredFieldValidator ID="rfvCategorie" runat="server" ControlToValidate="txtCategorie" ErrorMessage="Required" Display="Static" SetFocusOnError="true" />
                                    </EditItemTemplate>
                                </asp:TemplateField>                                                                                                                
                            </Fields>
                        </asp:DetailsView>
                        <div class="footer">
                            <asp:LinkButton ID="btnSave" runat="server" 
                                Text="Save" OnClick="BtnSave_Click" CausesValidation="true"
                             />
                            <asp:LinkButton ID="LinkButton1" runat="server" 
                                Text="Close" CausesValidation="false" 
                            />
                        </div>                    
                    </ContentTemplate>                
                </asp:UpdatePanel>             
            </asp:Panel>
     
              <!--=============================================================================================================================================================================-->
        </form>
    </body>
    </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
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
     
    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
     
        protected void BtnSave_Click(object sender, EventArgs args)
        {/*
            if (this.Page.IsValid)
            {
                //  move the data back to the data object
                this.dvCustomerDetail.UpdateItem(false);
                this.dvCustomerDetail.Visible = false;
     
                //  hide the modal popup
                this.mdlPopup.Hide();
     
                //  add the css class for our yellow fade
                ScriptManager.GetCurrent(this).RegisterDataItem(
                    // The control I want to send data to
                    this.gvCustomers,
                    //  The data I want to send it (the row that was edited)
                    this.gvCustomers.SelectedIndex.ToString()
                );
     
                //  refresh the grid so we can see our changed
                this.gvCustomers.DataBind();
                this.updatePanel.Update();
            }*/
        }
     
        protected void GvCustomers_SelectedIndexChanged(object sender, EventArgs e)
        {
            //  set it to true so it will render
            this.dvCustomerDetail.Visible = true;
            //  force databinding
            this.dvCustomerDetail.DataBind();
            //  update the contents in the detail panel
            this.updPnlCustomerDetail.Update();
            //  show the modal popup
            this.mdlPopup.Show();
        }
     
        protected void OdsCustomerDetail_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            //  set the input parameter to the value of the selected index
            e.InputParameters["idCategorie"] =
                Convert.ToString(this.gvCustomers.DataKeys[this.gvCustomers.SelectedIndex].Value);
        }
     
    }

Discussions similaires

  1. probleme avec modalpopup et RequiredFieldValidator
    Par Msysteme dans le forum ASP.NET
    Réponses: 1
    Dernier message: 29/06/2010, 11h27
  2. Probleme avec la copie des surfaces
    Par Black_Daimond dans le forum DirectX
    Réponses: 3
    Dernier message: 09/01/2003, 10h33
  3. probleme avec la touche F10
    Par b.grellee dans le forum Langage
    Réponses: 2
    Dernier message: 15/09/2002, 22h04
  4. Probleme avec fseek
    Par Bjorn dans le forum C
    Réponses: 5
    Dernier message: 04/08/2002, 07h17
  5. [Kylix] probleme avec un imagelist
    Par NicoLinux dans le forum EDI
    Réponses: 4
    Dernier message: 08/06/2002, 23h06

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