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();
 
    }