How to change the 'edit' button to 'Update'+'Cancel' button in Gridview

Hi all,

I'm using a commandField 'edit' button in a Gridview which I hope to be changed to a 'update' and a 'cancel' button when the 'edit' button is pushed. My codes are as follow.  My problem is that I don't know what codes should be added to make the change I mentioned to happen.

THanks a lot for your assistance.


<%@ Page Language="VB" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""><%@ Import Namespace="" %><%@ Import Namespace="" %> <script runat="server">      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)        Dim C_str As String = "Data Source=localHost;Initial Catalog=adventureWorks;Integrated Security=True"        Dim conn As SqlConnection = New SqlConnection(C_str)        Dim sql As String = "select contactID,FirstName,LastName from Person.Contact"        Dim da As New SqlDataAdapter        da.SelectCommand = New SqlCommand(sql, conn)        Dim ds As New DataSet        da.Fill(ds, "contact")        GV_Rec.DataSource = ds        GV_Rec.DataBind()            End Sub     Protected Sub GV_Rec_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs)     End Sub</script> <html xmlns="" ><head runat="server">    <title>Untitled Page</title></head><body>    <form id="form1" runat="server">    <div>    <asp:GridView ID="GV_Rec" runat="server" AutoGenerateColumns="false" AllowPaging="True"  PageSize="12" Width="780" OnRowEditing="GV_Rec_RowEditing">    <HeaderStyle Font-Size="small" ForeColor="#FFFFCC" BackColor="#999999" HorizontalAlign="center" />    <RowStyle Font-Size="small" ForeColor="#330090" Font-Names="arial" HorizontalAlign="center" />    <AlternatingRowStyle BackColor="Beige" />    <EditRowStyle BackColor="blue" ForeColor="white" />        <Columns>        <asp:BoundField DataField="ContactID" HeaderText="IDl" ReadOnly="true"  />        <asp:BoundField DataField="FirstName" HeaderText="First name"  />        <asp:BoundField DataField="LastName" HeaderText="Last Name"  />        <asp:CommandField ShowEditButton="true" ButtonType="button" CausesValidation="False"   />      </Columns>    </asp:GridView>     </div>    </form></body></html>


2/2/2009 1:43:35 PM 72751 articles. 3 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 17

You need to set the EditIndex and then re-bind your GridView to its DataSource something like this: 

Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
	GridView1.EditIndex = e.NewEditIndex
	GridView1.DataSource = ???
End Sub

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

2/2/2009 2:18:29 PM


Keep this in the row editing event of the grid






2/2/2009 2:27:11 PM


Thank you very much ecbruck.. it works. I moved a small step forward and is now in the rowUpdating event after I press the 'update' button.

can you give me some hint on how to read in the (now updated row contents) from the gridview?  This should be good for me as I already know what goes further forward.

Thanks once again..


2/3/2009 3:12:31 AM

Assuming you place your primary key "ContactId" within the GridView.DataKeyNames property, you can retrieve your data like so: 

Protected Sub GV_Rec_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GV_Rec.RowUpdating
	Dim row As GridViewRow = GV_Rec.Rows(e.RowIndex)
	Dim contactId As Integer = Convert.ToInt32(GridView1.DataKeys(row.RowIndex).Value)
	Dim txtFirstName As TextBox = TryCast(row.Cells(1).Controls(0), TextBox)
	Dim txtLastName As TextBox = TryCast(row.Cells(2).Controls(0), TextBox)

	If txtFirstName IsNot Nothing AndAlso txtLastName IsNot Nothing Then
		Dim firstName As String = txtFirstName.Text
		Dim lastName As String = txtLastName.Text
	End If
End Sub

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

2/3/2009 1:19:16 PM

Similar Artilces:

Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/ GranParadiso/3.0a1 From URL: Note to readers: Hendrix gives...

Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\ to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified, it calls t/uni/, that, in, (when the path separators are '\'), the $file is '..\lib\unicore\To\' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

Name: L Lachowsky Email: e2brutus_10atyahoodotcom Product: Firefox Summary: ''' Comments: why duddn this surprise me... I change default server from IE to Mozilla, and then i get error messages. well, shud I decide to not get on my computer with Mozilla..or shud I risk security breeches with IE....hmmm at least i can get on the internet with IE Browser Details: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv: Gecko/2008120122 Firefox/3.0.5 From URL: Note to readers: Hendrix gives no expectation of a response to this fee...

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

table_info('','','','%') cannot return any types
I was recently confirming table_info special cases and discovered the case for getting table_types cannot work. table_info('','','','%') should return a list of table types but it returns a list of empty strings instead: my @types = $h->tables('', '', '', '%'); print "all types:\n", join("xxx\n", @types), "\n"; # should output something like: # "dbo" # "INFORMATION_SCHEMA" # "sys" # and actually outputs: xxx xxx It seems to be down to the following ...

'IN' Clause or 'OR'
Hello, [1]: select * from TABLEA where COL1 IN('value1','value2''valu3'....) [2]:select * from TABLEA where COL1 = 'value1' OR COL1= 'value2' OR COL1='valu3'. TABLEA is a huge table and it has non-clustered index on COL1. Among the above 2 queries, which query will give me the better performance or fast response and WHY? What is the difference between 'IN' and 'OR' clauses as for as Sybase Optimization is concerned. Which is the better one to be used on huge tables. Thanks. Mac An IN list is treated ...

Hello. I'm using defferent 5.6.0's for Win32. I wonder wheter following behaviour is intentional or not: d:\>perl -e "print 'b'..'c'" bc d:\>perl -e "print 'b'..'a'" bcdefghijklmnopqrstuvwxyz I expected empty list in latter case, like in perl -e "print 'bb'..'a'" <!ENTITY Vadim REALLIFE "Vadim V.Konovalov, St.Petersburg, Russia"> &Vadim; On Wed, Sep 20, 2000 at 03:14:41PM +0400, Konovalov, Vadim wrote: > Hello. > > I'm using defferent 5.6.0'...

'or' or 'union'
Hello I was just wondering, in general what is better to use, an 'or' clause in a select or a 'union' to join two selects together. Do both statements create work tables? Many thanks Alex I think OR will be better than union. because suppose u have 3 tables and using OR u can join table a and table b and table c so each table will have only one read. but using union you will join table a and table b and in another query of union u will use table (a or b) and table c so ur one read is more in union . Ramdas Alex Cheung wrote: > Hello > >...

'back' and 'forward' buttons
Name: iskoah Email: Product: Firefox 2 Beta 2 Summary: 'back' and 'forward' buttons Comments: i have always liked the back and forward butons as big icons. so you can just whip your mouse up and click it really quick. with this, the button is only the arrow image. and the rest of it is the drop-down menu. i would really like to have the buttons have a biger clicking space. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1b2) Gecko/20060821 Firefox/2.0b2 ...

'Retract' and 'Reassign' buttons
Hi All, There are two buttons 'Retract' and 'Reassign' are displayed for WFs on the following pages: -'Retract' is displayed on Requests and Approvals-->My Requests -'Reassign' is displayed on Approval form. Please provide the insight on this. Thanks & Regards Peeyush Awasthi -- awasthpe ------------------------------------------------------------------------ On 05/21/2009 01:56 PM, awasthpe wrote: > Hi All, > There are two buttons 'Retract' and 'Reassign' are displayed for WFs on > the following p...

Auto Changing of '\\' to '\'
I am executing the following commands against an Adaptive Server 7 database (I have tried in both PowerBuilder and ISQL): UPDATE "dbo"."packet_items" SET "document_name" = '\\psa_1\appdoc\PACKETS\Packing Lists\Packing List-Demo.doc' WHERE "packet_id" = 25 AND "item_id" = 1 ; select * from dbo.packet_items WHERE "packet_id" = 25 AND "item_id" = 1 ; When I receive the results from the update command the document_name field contains the value '\psa_1\appdoc\PACKETS\Packing Lists\Packing List-Demo.doc'...

link 'Enter' button from keyboard to gridview edititem 'Update'
Hi, I have a gridview which displays data from my database. Currently when you choose 'Edit' and make amendments to the data displayed then click 'Update' all works fine.If you click 'Edit' make you changes and then press enter on the keyboard the whole page refreshes and the changes made are not applied. Does anyone know how i can link the 'Enter' button from the keyboard to the Update link on the gridview? Thanks for your time. Jay  Make sure that for the following the form tag in the page has the id="Form1", an...

'Value' should be between 'minimum' and 'maximum'.
I'm attempting to invoke with parameters:  Dim thing2 As New mydelsubPBStep(AddressOf pbStep) Me.Invoke(thing2, "setMax", dt.Rows.Count)      <---- this is where the error occurs   the delegate looks like this: Private Delegate Sub mydelsubPBStep(ByVal mode As String, ByVal value As Integer)   the function it's calling looks like this:Private Sub pbStep(ByVal mode As String, ByVal value As Integer) Select Case mode.ToLower Case "clear" ProgressBar1.Value = 0 Case "step" ProgressBar1.PerformStep() L...

Web resources about - How to change the 'edit' button to 'Update'+'Cancel' button in Gridview -

Resources last updated: 1/22/2016 11:47:35 PM