473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

DataGrid Key Field - Actual Value

Hi, could someone either please tell me or point me in
the right direction.

I have a DataGrid on a page with the DataKeyField="ID".
The grid displays checkboxes for each record. I have an
<asp:Button> on the page. In the handle for the button
click, when I determine if the checkbox is checked (by
interating thru all the rows of the DataGrid, how do I
get the actual value of ID so that I can pass the value
to my stored procedures?

code looks something like this:
DataGrid scDG;
// binding ....

int count = scDg.Items.Count;
int id;
for loop...
id = ????
end for loop
Thanks,
Prince
Nov 18 '05 #1
3 3212
Prince wrote:
I have a DataGrid on a page with the DataKeyField="ID".
The grid displays checkboxes for each record. <snip> how do I
get the actual value of ID so that I can pass the value
to my stored procedures?


'VB.NET
Dim ID as Integer = Convert.ToInt32(DataGridID.DataKeys(index))

// C#
int ID = Convert.ToInt32(DataGridID.DataKeys[index]);
So, if you're looping through the Items collection, the index would be
the current loop index. If you're in a DataGrid *Command event handler
(like UpdateCommand, or DeleteCommand), you'd use the index of the row
that triggered the event (e.Item.ItemIndex).

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
Nov 18 '05 #2
Funny. That was exactly what I had but thought it wasn't
working. I realized that the records were being deleted
in the back but the page wasn't being refreshed properly.

Thanks,
Prince
-----Original Message-----
Prince wrote:
I have a DataGrid on a page with the DataKeyField="ID". The grid displays checkboxes for each record. <snip> how do I get the actual value of ID so that I can pass the value to my stored procedures?
'VB.NET
Dim ID as Integer = Convert.ToInt32(DataGridID.DataKeys

(index))
// C#
int ID = Convert.ToInt32(DataGridID.DataKeys[index]);
So, if you're looping through the Items collection, the index would bethe current loop index. If you're in a DataGrid *Command event handler(like UpdateCommand, or DeleteCommand), you'd use the index of the rowthat triggered the event (e.Item.ItemIndex).

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
.

Nov 18 '05 #3
Prince wrote:
Funny. That was exactly what I had but thought it wasn't
working. I realized that the records were being deleted
in the back but the page wasn't being refreshed properly.


Yeah, whenever deleting or updating data you need to make sure to rebind
the data to the DataGrid.

Glad to hear you got it working! :-)

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPMessageboard.com
http://www.ASPFAQs.com

* When you think ASP, think 4GuysFromRolla.com!
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Wishing I was skiing mom | last post by:
In form1, which is an item master maintenance screen, I have a button which launches form2. Form2 contains an item master datagrid. After the user double-clicks the desired item record in form2 I...
0
by: Johann Blake | last post by:
I have a dataset that I bind to two different datagrids. The dataset contains 2 tables. One is the main table used to store what I call session data which includes a Country field where the ID of a...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
9
by: Paul | last post by:
Hi I have a data grid with a hyperlink column. the colum has numbers like 00001,000002, ect. Just wondering how to get the text value of the cell as tempstring =...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
13
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid, another cell in the datagrid is filled with a value....
2
by: Arif | last post by:
Very strange problem: Executing my query against MS Access database using OleDbProvider for Access, I am getting the value for first two columns '0' instead of '1' in DataGrid. But if I connect to...
13
by: shookim | last post by:
I don't care how one suggests I do it, but I've been searching for days on how to implement this concept. I'm trying to use some kind of grid control (doesn't have to be a grid control, whatever...
0
by: Sudhir Kesharwani | last post by:
Hi All, I am developing a custom grid view control, which displays a checkbox...grid control is bound to a datasource. i am writing a custom method for the datagrid, where in user can get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.