TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
bani marc
NA
54
2.5k
Gridview edit button is firing only once
Sep 19 2017 10:25 AM
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 :
<
div
class
=
"row"
>
<
div
class
=
"col-md-12"
>
<
asp:GridView
ID
=
"GridView1"
runat
=
"server"
CssClass
=
"footable"
AutoGenerateColumns
=
"false"
Style
=
"max-width:500px"
>
<
Columns
>
<
asp:TemplateField
HeaderText
=
"Image"
>
<
ItemTemplate
>
<
asp:Image
ID
=
"Image3"
runat
=
"server"
Height
=
"100"
Width
=
"100"
ImageUrl
=
'<%# Eval("id_perso", "ImageCSharp2.aspx?ImageID={0}")%>'
/>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:BoundField
DataField
=
"id_perso"
HeaderText
=
"ID"
ItemStyle-HorizontalAlign
=
"center"
Visible
=
"false"
/>
<
asp:BoundField
DataField
=
"statut"
HeaderText
=
"Statut"
ItemStyle-HorizontalAlign
=
"center"
/>
<
asp:BoundField
DataField
=
"nom_perso"
HeaderText
=
"Nom"
ItemStyle-HorizontalAlign
=
"center"
/>
<
asp:BoundField
DataField
=
"prenom_perso"
HeaderText
=
"Prénom"
ItemStyle-HorizontalAlign
=
"center"
/>
<
asp:BoundField
DataField
=
"adresse_perso"
HeaderText
=
"Adresse"
ItemStyle-HorizontalAlign
=
"center"
/>
<
asp:BoundField
DataField
=
"code_postal_perso"
HeaderText
=
"Code Postal"
ItemStyle-HorizontalAlign
=
"center"
/>
<
asp:BoundField
DataField
=
"ville_perso"
HeaderText
=
"Ville"
ItemStyle-HorizontalAlign
=
"center"
/>
<
asp:BoundField
DataField
=
"tel_perso"
HeaderText
=
"Téléphone"
ItemStyle-HorizontalAlign
=
"center"
/>
<
asp:BoundField
DataField
=
"mail_perso"
HeaderText
=
"Email"
ItemStyle-HorizontalAlign
=
"center"
/>
<
asp:TemplateField
HeaderText
=
""
>
<
ItemTemplate
>
<
asp:Button
id
=
"btnEdit"
runat
=
"server"
Text
=
"Editer"
OnClick
=
"Edit"
CommandArgument
=
'<%# Eval("id_perso") %>'
class
=
"btn btn-primary"
/>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:TemplateField
HeaderText
=
""
>
<
ItemTemplate
>
<
asp:Button
ID
=
"btnSupprimer"
runat
=
"server"
Text
=
"Supprimer"
OnClick
=
"Delete"
CommandArgument
=
'<%# Eval("id_perso") %>'
CssClass
=
"btn btn-danger"
/>
</
ItemTemplate
>
</
asp:TemplateField
>
</
Columns
>
</
asp:GridView
>
</
div
>
</
div
>
<
asp:LinkButton
ID
=
"lnkFake"
runat
=
"server"
>
</
asp:LinkButton
>
<
asp:Panel
ID
=
"pnlAddUpdatePersonnelDetails"
runat
=
"server"
CssClass
=
"modalPopup"
Style
=
"Display:none;"
>
<
div
style
=
"overflow-y:auto;overflow-x:hidden;max-height:450px;width:600px;"
>
<
div
class
=
"modal-header"
>
<
asp:Label
ID
=
"lblHeading"
runat
=
"server"
CssClass
=
"modal-title"
>
</
asp:Label
>
</
div
>
<
div
class
=
"modal-body"
>
<
div
class
=
"col-md-3"
>
<
asp:Image
ID
=
"Image2"
runat
=
"server"
ImageAlign
=
"Middle"
Width
=
"100px"
Height
=
"100px"
Style
=
"border:1px solid black;"
/>
<
asp:TextBox
ID
=
"txtStatut"
runat
=
"server"
Text
=
"Label"
>
</
asp:TextBox
>
</
div
>
<
div
class
=
"col-md-9"
>
<
div
class
=
"form-group col-md-12"
>
<
div
class
=
"col-md-6"
>
<
label
for
=
"txtGenre"
runat
=
"server"
>
Genre :
</
label
>
</
div
>
<
div
class
=
"col-md-6"
>
<
asp:TextBox
ID
=
"txtGenre"
runat
=
"server"
CssClass
=
"form-control"
ReadOnly
=
"true"
>
</
asp:TextBox
>
</
div
>
</
div
>
<
div
class
=
"form-group col-md-12"
>
<
div
class
=
"form-group"
>
<
div
class
=
"row"
>
<
div
class
=
"col-md-3"
>
<
label
for
=
"txtNom"
>
Nom
</
label
>
</
div
>
<
div
class
=
"col-md-6"
>
<
asp:TextBox
ID
=
"txtNom"
runat
=
"server"
CssClass
=
"form-control"
placeholder
=
"Nom"
Width
=
"150px"
>
</
asp:TextBox
>
</
div
>
</
div
>
</
div
>
</
div
>
<
div
class
=
"form-group col-md-12"
>
<
div
class
=
"col-md-6"
>
<
label
for
=
"txtPrenom"
>
Prénom :
</
label
>
</
div
>
<
div
class
=
"col-md-6"
>
<
asp:TextBox
ID
=
"txtPrenom"
runat
=
"server"
CssClass
=
"form-control"
Width
=
"150px"
ReadOnly
=
"false"
>
</
asp:TextBox
>
</
div
>
</
div
>
<
div
class
=
"form-group col-md-12"
>
<
div
class
=
"col-md-6"
>
<
label
for
=
"FileUpload2"
>
Modifier la photo :
</
label
>
</
div
>
<
div
class
=
"col-md-6"
>
<
asp:FileUpload
ID
=
"FileUpload2"
runat
=
"server"
CssClass
=
"btn btn-warning"
/>
</
div
>
</
div
>
</
div
>
</
div
>
<
div
align
=
"center"
class
=
"modal-footer"
>
<
div
class
=
"row"
>
<
div
class
=
"col-md-12"
>
<
asp:HiddenField
ID
=
"hfAddEditPersonnelId"
runat
=
"server"
Value
=
"0"
/>
<
asp:HiddenField
ID
=
"hfAddEdit"
runat
=
"server"
Value
=
"ADD"
/>
<
asp:Button
ID
=
"btnSave"
runat
=
"server"
Text
=
"Sauvegarder"
OnClick
=
"Save"
CssClass
=
"btn btn-success"
ValidationGroup
=
"Personnel"
/>
<
button
id
=
"btnCancel"
runat
=
"server"
class
=
"btn btn-primary"
>
Annuler
</
button
>
</
div
>
</
div
>
</
div
>
</
div
>
</
asp:Panel
>
<
uc:ModalPopupExtender
ID
=
"mpeAddUpdatePersonnel"
runat
=
"server"
PopupControlID
=
"pnlAddUpdatePersonnelDetails"
TargetControlID
=
"lnkFake"
BehaviorID
=
"mpeAddUpdatePersonnel"
CancelControlID
=
"btnCancel"
BackgroundCssClass
=
"modalBackground"
>
</
uc:ModalPopupExtender
>
My code behind :
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
BindPerso();
}
}
private
void
BindPerso()
{
DataTable dt =
new
DataTable();
using
(RestauDBEntities1 db =
new
RestauDBEntities1())
{
if
(db.PERSONNEL.Count() > 0)
{
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();
GridView1.DataBind();
}
else
{
GridView1.DataSource =
null
;
GridView1.DataBind();
}
}
}
public
void
Edit(
object
sender, EventArgs e)
{
//Label2.Visible = false;
lblHeading.Text =
"Update Employee Details"
;
hfAddEditPersonnelId.Value = (sender
as
Button).CommandArgument;
try
{
using
(RestauDBEntities1 db =
new
RestauDBEntities1())
{
if
(db.PERSONNEL.Count() > 0)
{
int
persoID = Convert.ToInt16(hfAddEditPersonnelId.Value);
PERSONNEL persoObject = (from p
in
db.PERSONNEL
where p.id_perso == persoID
select p).FirstOrDefault();
txtNom.Text = Convert.ToString(persoObject.nom_perso);
txtPrenom.Text = Convert.ToString(persoObject.prenom_perso);
byte
[] barrImg = (
byte
[])persoObject.picture;
if
(barrImg !=
null
&& barrImg.Length > 0)
{
string
base64String = Convert.ToBase64String(barrImg, 0, barrImg.Length);
Image2.ImageUrl =
"data:image/jpg;base64,"
+ base64String;
}
mpeAddUpdatePersonnel.Show();
}
}
}
catch
(Exception ex)
{
Label2.Text = ex.Message.ToString();
Label2.Visible =
true
;
}
}
Reply
Answers (
2
)
how to insert data from grideview to the database
.net Developer professioal