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
Priyanka Singh
690
1.4k
675.8k
Error while deletion of data in gridview.
May 1 2019 4:20 AM
The Declarative Approach
While using TemplateField, we can directly use the OnClientClick event of the LinkButton Server control and call JavaScript confirm function, as given below.
<ItemTemplate>
<asp:LinkButtonID=
"lnkDelete"
runat=
"server"
OnClick=
"lnkDelete _Click"
OnClientClick=
"return confirmOnDelete('');"
>Delete</asp:LinkButton>
</ItemTemplate>
The Code behind Approach
The Code Behind approach is almost the same, as we did using the RowDataBound event to access the ShowDeleteButton. The output is given below.
protected
void
gvEmployee_RowDataBound(
object
sender, GridViewRowEventArgs e)
{
if
(e.Row.RowState != DataControlRowState.Edit)
// check for RowState
{
if
(e.Row.RowType == DataControlRowType.DataRow)
//check for RowType
{
string
id = gvEmployee.DataKeys[e.Row.RowIndex].Value.ToString();
//cast the ShowDeleteButton link to linkbutton
LinkButton lb = (LinkButton)e.Row.Cells[4].FindControl(
"lnkDelete"
);
if
(lb !=
null
)
{
//attach the JavaScript function and pass the ID as the paramter
lb.Attributes.Add(
"Onclick"
,
"return confirmOnDelete('"
+ id +
"');"
);
}
}
}
}
It shows as error
Reply
Answers (
7
)
Why Context Return Null in entity framework
doc to pdf in mvc