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
Mohan
1.7k
27
2.5k
gridview command field image button delete not firing
Dec 3 2020 6:05 PM
Hi, I'm implementing gridview crud operation. I used command field with button type button, all the functions (edit, update,delete) worked properly. But when I changed command field button type to image, delete function is not firing. When I click on Delete icon, Javascript alert is coming, and when I click ok, it is not firing OnRowDeleting function, Below is my code
<asp:GridView ID=
"grdCenterVisitDate"
runat=
"server"
AutoGenerateColumns=
"false"
OnRowDataBound=
"OnRowDataBound"
DataKeyNames=
"CenterVisitID"
OnRowEditing=
"OnRowEditing"
OnRowCancelingEdit=
"OnRowCancelingEdit"
PageSize =
"5"
AllowPaging =
"true"
OnPageIndexChanging =
"OnPaging"
OnRowUpdating=
"OnRowUpdating"
OnRowDeleting=
"OnRowDeleting"
EmptyDataText=
"No records has been added."
>
<Columns>
<asp:TemplateField HeaderText=
"Center Visit date"
>
<ItemTemplate>
<asp:Label ID=
"lblName"
runat=
"server"
Text=
'<%# Eval("CenterVisitDate") %>'
></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID=
"txtCenterVisitDate"
runat=
"server"
ValidationGroup=
"vgManageVisitDate"
Text=
'<%# Eval("CenterVisitDate") %>'
></asp:TextBox>
<asp:RequiredFieldValidator ID=
"rfvManageVisitDate"
runat=
"server"
ControlToValidate=
"txtCenterVisitDate"
ErrorMessage=
"Date is required"
Display=
"Dynamic"
ValidationGroup=
"vgManageVisitDate"
></asp:RequiredFieldValidator>
<ACT:CalendarExtender ID=
"cetxtStartDate"
runat=
"server"
TargetControlID=
"txtCenterVisitDate"
></ACT:CalendarExtender>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=
"CenterVisitType"
>
<ItemTemplate>
<asp:Label ID=
"lblCenterVisitType"
runat=
"server"
Text=
'<%# Eval("CenterVisitType") %>'
></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat=
"server"
ID=
"ddlCenterVisit"
SelectedValue=
'<%# Bind("CenterVisitTypeID") %>'
>
<asp:ListItem Text=
"In-Person Class hours"
Value=
"1"
></asp:ListItem>
<asp:ListItem Text=
"In-Person Consultation"
Value=
"2"
></asp:ListItem>
<asp:ListItem Text=
"On-Line Consultation"
Value=
"3"
></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType=
"Image"
ShowEditButton=
"true"
ShowCancelButton=
"true"
ShowDeleteButton=
"true"
ValidationGroup=
"vgManageVisitDate"
EditImageUrl=
"~/Images/site/goals/icon-edit-sm.png"
DeleteImageUrl=
"~/Images/site/goals/icon-delete-sm.png"
UpdateImageUrl=
"~/Images/site/goals/icon-update-sm.png"
CancelImageUrl=
"~/Images/site/goals/icon-cancel-sm.png"
ControlStyle-CssClass=
"btn btn-cv-edit"
/>
</Columns>
</asp:GridView>
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(Request.QueryString[
"CenterID"
] !=
null
)
strCenterID = Request.QueryString[
"CenterID"
];
if
(!IsPostBack)
{
////txtDate1.StartDate = DateTime.Now;
fillCenterVisitDate();
}
else
dashboardID = 2;
}
private
void
fillCenterVisitDate()
{
DataSet ds =
new
DataSet();
ds = gdh.GetCenterVisitDateByDashboardID(2);
grdCenterVisitDate.DataSource = ds;
grdCenterVisitDate.DataBind();
}
#region CenterVisitDateGrid
protected
void
OnRowEditing(
object
sender, GridViewEditEventArgs e)
{
grdCenterVisitDate.EditIndex = e.NewEditIndex;
this
.fillCenterVisitDate();
}
protected
void
OnRowUpdating(
object
sender, GridViewUpdateEventArgs e)
{
GridViewRow row = grdCenterVisitDate.Rows[e.RowIndex];
int
gridId = Convert.ToInt32(grdCenterVisitDate.DataKeys[e.RowIndex].Values[0]);
DateTime centerVisitDate = Convert.ToDateTime((row.FindControl(
"txtCenterVisitDate"
)
as
TextBox).Text);
Int16 CenterVisit = Convert.ToInt16((row.FindControl(
"ddlCenterVisit"
)
as
DropDownList).SelectedValue);
int
i = gdh.updateCenterVisitDate(gridId, CenterVisit, centerVisitDate, user.UserID);
grdCenterVisitDate.EditIndex = -1;
this
.fillCenterVisitDate();
}
protected
void
OnRowCancelingEdit(
object
sender, EventArgs e)
{
grdCenterVisitDate.EditIndex = -1;
this
.fillCenterVisitDate();
}
protected
void
OnRowDeleting(
object
sender, GridViewDeleteEventArgs e)
{
int
centerVisitId = Convert.ToInt32(grdCenterVisitDate.DataKeys[e.RowIndex].Values[0]);
int
i = gdh.DelCenterVisit(centerVisitId);
this
.fillCenterVisitDate();
}
protected
void
OnRowDataBound(
object
sender, GridViewRowEventArgs e)
{
if
(e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex != grdCenterVisitDate.EditIndex)
{
(e.Row.Cells[2].Controls[2]
as
LinkButton).Attributes[
"onclick"
] =
"return confirm('Do you want to delete this row?');"
;
}
}
protected
void
OnPaging(
object
sender, GridViewPageEventArgs e)
{
grdCenterVisitDate.PageIndex = e.NewPageIndex;
this
.fillCenterVisitDate();
}
#endregion
Reply
Answers (
1
)
Asp .Net MVC project Web Deployment to hosting site
Error Report Viewer