2
Reply

Gridview edit button is firing only once

bani marc

bani marc

Sep 19 2017 10:25 AM
210
Hi everyone. Maybe someone have the solution for my probleme. I have a gridview with different columns. One of them is for thye edit button which display a popup details view. Everything works fine the first time I click on the edit button. But if I click again on the same or another edit button, nothing happens. The debugger says nothing. All the variable seems to pass without issues. I don't know what to do to solve my issue. Is someone has a idea ? Thank in advance
My aspx code :
  1. <div class="row">  
  2. <div class="col-md-12">  
  3. <asp:GridView ID="GridView1" runat="server" CssClass="footable" AutoGenerateColumns="false" Style="max-width:500px">  
  4. <Columns>  
  5. <asp:TemplateField HeaderText="Image">  
  6. <ItemTemplate>  
  7. <asp:Image ID="Image3" runat="server" Height = "100" Width = "100" ImageUrl = '<%# Eval("id_perso", "ImageCSharp2.aspx?ImageID={0}")%>' />  
  8. </ItemTemplate>  
  9. </asp:TemplateField>  
  10. <asp:BoundField DataField="id_perso" HeaderText="ID" ItemStyle-HorizontalAlign="center" Visible="false" />  
  11. <asp:BoundField DataField="statut" HeaderText="Statut" ItemStyle-HorizontalAlign="center" />  
  12. <asp:BoundField DataField="nom_perso" HeaderText="Nom" ItemStyle-HorizontalAlign="center" />  
  13. <asp:BoundField DataField="prenom_perso" HeaderText="Prénom" ItemStyle-HorizontalAlign="center" />  
  14. <asp:BoundField DataField="adresse_perso" HeaderText="Adresse" ItemStyle-HorizontalAlign="center" />  
  15. <asp:BoundField DataField="code_postal_perso" HeaderText="Code Postal" ItemStyle-HorizontalAlign="center" />  
  16. <asp:BoundField DataField="ville_perso" HeaderText="Ville" ItemStyle-HorizontalAlign="center" />  
  17. <asp:BoundField DataField="tel_perso" HeaderText="Téléphone" ItemStyle-HorizontalAlign="center" />  
  18. <asp:BoundField DataField="mail_perso" HeaderText="Email" ItemStyle-HorizontalAlign="center" />  
  19. <asp:TemplateField HeaderText="">  
  20. <ItemTemplate>  
  21. <asp:Button id="btnEdit" runat="server" Text="Editer" OnClick="Edit" CommandArgument='<%# Eval("id_perso") %>' class="btn btn-primary" />  
  22. </ItemTemplate>  
  23. </asp:TemplateField>  
  24. <asp:TemplateField HeaderText="">  
  25. <ItemTemplate>  
  26. <asp:Button ID="btnSupprimer" runat="server" Text="Supprimer" OnClick="Delete" CommandArgument='<%# Eval("id_perso") %>' CssClass="btn btn-danger" />  
  27. </ItemTemplate>  
  28. </asp:TemplateField>  
  29. </Columns>  
  30. </asp:GridView>  
  31. </div>  
  32. </div>  
  33. <asp:LinkButton ID="lnkFake" runat="server"></asp:LinkButton>  
  34. <asp:Panel ID="pnlAddUpdatePersonnelDetails" runat="server" CssClass="modalPopup" Style="Display:none;">  
  35. <div style="overflow-y:auto;overflow-x:hidden;max-height:450px;width:600px;">  
  36. <div class="modal-header">  
  37. <asp:Label ID="lblHeading" runat="server" CssClass="modal-title"></asp:Label>  
  38. </div>  
  39. <div class="modal-body">  
  40. <div class="col-md-3">  
  41. <asp:Image ID="Image2" runat="server" ImageAlign="Middle" Width="100px" Height="100px" Style="border:1px solid black;"/>  
  42. <asp:TextBox ID="txtStatut" runat="server" Text="Label"></asp:TextBox>  
  43. </div>  
  44. <div class="col-md-9">  
  45. <div class="form-group col-md-12">  
  46. <div class="col-md-6">  
  47. <label for="txtGenre" runat="server">Genre :</label>  
  48. </div>  
  49. <div class="col-md-6">  
  50. <asp:TextBox ID="txtGenre" runat="server" CssClass="form-control" ReadOnly="true"></asp:TextBox>  
  51. </div>  
  52. </div>  
  53. <div class="form-group col-md-12">  
  54. <div class="form-group">  
  55. <div class="row">  
  56. <div class="col-md-3">  
  57. <label for="txtNom">  
  58. Nom  
  59. </label>  
  60. </div>  
  61. <div class="col-md-6">  
  62. <asp:TextBox ID="txtNom" runat="server" CssClass="form-control" placeholder="Nom" Width="150px"></asp:TextBox>  
  63. </div>  
  64. </div>  
  65. </div>  
  66. </div>  
  67. <div class="form-group col-md-12">  
  68. <div class="col-md-6">  
  69. <label for="txtPrenom">  
  70. Prénom :  
  71. </label>  
  72. </div>  
  73. <div class="col-md-6">  
  74. <asp:TextBox ID="txtPrenom" runat="server" CssClass="form-control" Width="150px" ReadOnly ="false"></asp:TextBox>  
  75. </div>  
  76. </div>  
  77. <div class="form-group col-md-12">  
  78. <div class="col-md-6">  
  79. <label for="FileUpload2">Modifier la photo :</label>  
  80. </div>  
  81. <div class="col-md-6">  
  82. <asp:FileUpload ID="FileUpload2" runat="server" CssClass="btn btn-warning"/>  
  83. </div>  
  84. </div>  
  85. </div>  
  86. </div>  
  87. <div align="center" class="modal-footer">  
  88. <div class="row">  
  89. <div class="col-md-12">  
  90. <asp:HiddenField ID="hfAddEditPersonnelId" runat="server" Value="0" />  
  91. <asp:HiddenField ID="hfAddEdit" runat="server" Value="ADD" />  
  92. <asp:Button ID="btnSave" runat="server" Text="Sauvegarder" OnClick="Save" CssClass="btn btn-success" ValidationGroup="Personnel" />  
  93. <button id="btnCancel" runat="server" class="btn btn-primary">Annuler</button>  
  94. </div>  
  95. </div>  
  96. </div>  
  97. </div>  
  98. </asp:Panel>  
  99. <uc:ModalPopupExtender ID="mpeAddUpdatePersonnel" runat="server" PopupControlID="pnlAddUpdatePersonnelDetails" TargetControlID="lnkFake" BehaviorID="mpeAddUpdatePersonnel" CancelControlID="btnCancel" BackgroundCssClass="modalBackground" ></uc:ModalPopupExtender>  
My code behind :
  1. protected void Page_Load(object sender, EventArgs e)  
  2. {  
  3. if (!IsPostBack)  
  4. {  
  5. BindPerso();  
  6. }  
  7. }  
  8. private void BindPerso()  
  9. {  
  10. DataTable dt = new DataTable();  
  11. using (RestauDBEntities1 db = new RestauDBEntities1())  
  12. {  
  13. if (db.PERSONNEL.Count() > 0)  
  14. {  
  15. GridView1.DataSource = (from pers in db.PERSONNEL select new { pers.id_perso, pers.statut, pers.nom_perso, pers.prenom_perso, pers.adresse_perso, pers.code_postal_perso, pers.ville_perso, pers.date_entree_perso, pers.salaire_brut, pers.tel_perso, pers.mail_perso, pers.secu_perso, pers.date_naissance, pers.lieu_naissance, pers.genre, pers.pseudo, pers.mdp, pers.picture, pers.observation }).ToList();  
  16. GridView1.DataBind();  
  17. }  
  18. else  
  19. {  
  20. GridView1.DataSource = null;  
  21. GridView1.DataBind();  
  22. }  
  23. }  
  24. }  
  25. public void Edit(object sender, EventArgs e)  
  26. {  
  27. //Label2.Visible = false;  
  28. lblHeading.Text = "Update Employee Details";  
  29. hfAddEditPersonnelId.Value = (sender as Button).CommandArgument;  
  30. try  
  31. {  
  32. using (RestauDBEntities1 db = new RestauDBEntities1())  
  33. {  
  34. if(db.PERSONNEL.Count() > 0)  
  35. {  
  36. int persoID = Convert.ToInt16(hfAddEditPersonnelId.Value);  
  37. PERSONNEL persoObject = (from p in db.PERSONNEL  
  38. where p.id_perso == persoID  
  39. select p).FirstOrDefault();  
  40. txtNom.Text = Convert.ToString(persoObject.nom_perso);  
  41. txtPrenom.Text = Convert.ToString(persoObject.prenom_perso);  
  42. byte[] barrImg = (byte[])persoObject.picture;  
  43. if (barrImg != null && barrImg.Length > 0)  
  44. {  
  45. string base64String = Convert.ToBase64String(barrImg, 0, barrImg.Length);  
  46. Image2.ImageUrl = "data:image/jpg;base64," + base64String;  
  47. }  
  48. mpeAddUpdatePersonnel.Show();  
  49. }  
  50. }  
  51. }  
  52. catch (Exception ex)  
  53. {  
  54. Label2.Text = ex.Message.ToString();  
  55. Label2.Visible = true;  
  56. }  
  57. }

Answers (2)