.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Alert messgae in popup in GridView while edit

Posted By: Ramesh     Posted Date: July 30, 2010    Points:2   Category :ASP.Net
Hi,

can i pop up an alert message on the edit button of the Gridview and how can i do it in asp.net?

Regards,
Ramesh



Responses
Author: Sunil Yadav       [Moderator]      
Posted Date: July 30, 2010     Points: 5   

Hi,


You can use the below code for edit confirmation.


1. Add a command argument on delete button.
<asp:GridView ID="GridView1" runat="server" DataKeyNames="Host" AllowPaging="True"
AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound">

<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" CommandName="Edit" runat="server" Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</GridView>


2. Add a attribute on GridView1_RowDataBound event to LinkButton lnkDelete.

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

LinkButton lnkEdit= (LinkButton)e.Row.FindControl("lnkEdit");

lnkEdit.Attributes.Add("onclick", "javascript:return " +
"confirm('Are you sure you want to update record for this " +
DataBinder.Eval(e.Row.DataItem, "Host") + "')");

}


3. Now perform a delete operation on GridView1_RowCommand event. You can also do it on GridView1_Editing event.

 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridView gv = (GridView)sender;


if (e.CommandName == "Edit")
{

// Update record here...........
}
}


hope it helps.




Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend