Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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
 
Old January 9th, 2007, 09:59 AM
Registered User
 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataKeys to update and delete data in DataGrid

Hello All,

My question is what are datakeys, how to use them?, and a vb code to show how i can update and delete from DataGrid by using them...

Thanks,:)

Diana
 
Old January 9th, 2007, 10:26 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

If you set the DataKeyField of the datagrid to a column in the Datasource, a DataKeys collection is created that maintains all of the key values for each row.

If you are using some sort of Normalized Database the value that you are placing in the DataKeyField should be the Primary Key of the datasource, thus making it unique, so that you can preform SQL Statements against X Row. To access this in a code you would do something like this:

Private Sub dgDelete(ByVal Sender As Object, e as DataGridCommandEventArgs)
    Dim sDatabasePK as string = [datagrid_object].DataKeys(e.Item.ItemIndex)
    //Do something with the pk value
    //Rebind the datagrid
End Sub

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old January 9th, 2007, 11:15 AM
Registered User
 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks,

Comd.Parameters("@Id").Value = DataGrid.DataKeys(CInt(E.Item.ItemIndex))

Can I ask what is CInt?

Diana
 
Old January 9th, 2007, 11:27 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi

Basically the role of CInt is to convert a value into integer type.

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.
 
Old January 9th, 2007, 11:35 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Yes,
   CInt is the same as Convert.ToInt32() and is a VB only function. C# developers have to use Convert.ToInt32 or add a reference to Microsoft.VisualBasic to access that function. Though the only time that I have ever imported that namespace into a C# app is when I need to use the VB IsNumeric() function since C# doesnt have an IsNumeric() function =[

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature





Similar Threads
Thread Thread Starter Forum Replies Last Post
INSERT, UPDATE, DELETE dagad ASP.NET 2.0 Professional 0 September 27th, 2006 01:22 AM
How can i Insert , delete data from datagrid ?? jay4ever_2000 ASP.NET 1.0 and 1.1 Professional 1 February 17th, 2006 03:35 PM
How to Update and Delete in Datagrid Through comma Rahul Gupta ASP.NET 1.x and 2.0 Application Design 1 September 30th, 2005 11:42 PM
DataGrid and DataKeys Problem booksnore2 General .NET 4 July 6th, 2004 11:10 AM
Delete and Update Permissions benskywalker Classic ASP Databases 1 September 29th, 2003 03:13 PM





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