Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 20th, 2006, 07:58 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default edit gridview

Hi ,
    I have one doubt regarding gridview edit operation.

    I want to execute a javascript validation before the user hits on the update link. how will I achive that?

    If u have any idea,pls let me know.

this is my gridview code

<asp:GridView ID="dgDesignation" runat="server" Width="463px" AutoGenerateColumns="False"
         DataKeyNames="ID" AllowPaging=True PageSize=15 Height="138px"
        >
            <Columns>
                <asp:BoundField HeaderText = "Designation" DataField="Designation" />
                <asp:CommandField ShowEditButton="True" />
                <asp:TemplateField>
                <ItemTemplate>
                <asp:LinkButton ID="lnkDelete" CommandName="Delete" runat="server">Delete</asp:LinkButton>
                </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <HeaderStyle CssClass="tblFormHeaders" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>

Thanks,
Anurag

Reply With Quote
  #2 (permalink)  
Old June 20th, 2006, 11:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Say for example, this is how you confirm a deletion. You can do other things like this:

http://www.dotnetjohn.com/articles.aspx?articleid=68

Brian
Reply With Quote
  #3 (permalink)  
Old June 20th, 2006, 12:41 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

For a ASP.NET 2 solution, you can also use OnClientClick, described near the end of this article:

http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=355

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Reply With Quote
  #4 (permalink)  
Old June 21st, 2006, 03:21 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi All,
Thanks..
I got the solution. I used the following code

Protected Sub dgDesignation_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles dgDesignation.RowDataBound
            If e.Row.RowType = DataControlRowType.DataRow Then
                For Each ctl As Control In e.Row.Cells(1).Controls

                    If TypeOf ctl Is LinkButton Then
                        Dim link As LinkButton = CType(ctl, LinkButton)
                        If link.CommandName = "Update" Then
                            link.OnClientClick = "return ValidateUpdate('" + e.Row.Cells(0).Controls(0).ClientID + "');"

                        End If

                    End If

                Next

                Dim l As LinkButton
                l = CType(e.Row.FindControl("lnkDelete"), LinkButton)
                l.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to delete this record?')")
            End If
        End Sub


Ragards,
Anurag

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Gridview to Edit NOT DetailsView ? kalel_4444 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 December 4th, 2008 11:36 PM
Can not Edit gridview having TemplateField coolcoder2007 .NET Framework 2.0 4 March 6th, 2008 06:36 AM
GridView edit problem mike72 ASP.NET 2.0 Basics 8 January 3rd, 2007 07:59 PM
edit item in gridview al-hijjawi Visual Studio 2005 0 December 27th, 2006 03:20 PM
edit gridview anurag_ur ASP.NET 2.0 Basics 0 June 20th, 2006 07:57 AM



All times are GMT -4. The time now is 08:24 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.