473,385 Members | 1,597 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,385 software developers and data experts.

Assoicate a primary key with a checkbox inside a datagrid

Hi everyone, could someone please recommend a way to do the following.

I have a datagrid which contains a bound template column consisting of
checkbox and a string pulled from a database table.
I want to be able to associate the primary key of the database table with
the checkbox so that when someone checks a box I can iterate through all the
checkboxs and identify the associated value in the database.

Thanks in advance
Mark

Nov 19 '05 #1
3 1720
Hi Mark,

In order to get parimary key value in a datagrid, you can set the datagrid's
DataKeyField = "Parimary_Key_Field_Name". And loop thru datagrid items

CheckBox ck;
foreach (DataGridItem item in datagrid.Items)
{
string pk_value = datagrid.DataKeys[item.Item.ItemIndex].ToString();
ck = (CheckBox)item.FindControl("ckBoxID");
bool checked = ck.Checked;
// process
}
HTH

Elton Wang
el********@hotmail.com
"Mark" wrote:
Hi everyone, could someone please recommend a way to do the following.

I have a datagrid which contains a bound template column consisting of
checkbox and a string pulled from a database table.
I want to be able to associate the primary key of the database table with
the checkbox so that when someone checks a box I can iterate through all the
checkboxs and identify the associated value in the database.

Thanks in advance
Mark

Nov 19 '05 #2
Hi all, I could not find an answer to my original question from anyone so I
just did a little hack

Basically, inside the itemtemplate I created a hidden text field which I
populated with the associated primary key for each record.

When I want to check if a checkbox has been checked and retrieve the primary
key I just did the looked for this hidden field and retrieved the primary
key value that was originally stored in it. Works a treat but I can't help
feeling that there must be a better way

Cheers
Mark
"Mark" <do**@spam.me> wrote in message
news:ur*************@TK2MSFTNGP14.phx.gbl...
Hi everyone, could someone please recommend a way to do the following.

I have a datagrid which contains a bound template column consisting of
checkbox and a string pulled from a database table.
I want to be able to associate the primary key of the database table with
the checkbox so that when someone checks a box I can iterate through all the checkboxs and identify the associated value in the database.

Thanks in advance
Mark

Nov 19 '05 #3
Ahh, that's it :) Thanks Elton
Cheers
Mark
"Elton W" <El****@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
Hi Mark,

In order to get parimary key value in a datagrid, you can set the datagrid's DataKeyField = "Parimary_Key_Field_Name". And loop thru datagrid items

CheckBox ck;
foreach (DataGridItem item in datagrid.Items)
{
string pk_value = datagrid.DataKeys[item.Item.ItemIndex].ToString();
ck = (CheckBox)item.FindControl("ckBoxID");
bool checked = ck.Checked;
// process
}
HTH

Elton Wang
el********@hotmail.com
"Mark" wrote:
Hi everyone, could someone please recommend a way to do the following.

I have a datagrid which contains a bound template column consisting of
checkbox and a string pulled from a database table.
I want to be able to associate the primary key of the database table with the checkbox so that when someone checks a box I can iterate through all the checkboxs and identify the associated value in the database.

Thanks in advance
Mark

Nov 19 '05 #4

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

Similar topics

0
by: Just D | last post by:
Hi All, Does anybody know how to write the following code? I have a database table with a few columns including: ID , "Task" , ForceRun . I need to show the DataGrid on the ASPX page with...
2
by: Sebi | last post by:
Hello all is it possible to add a checkbox in a DataGrid for Boolean Data? Thanks in advance
0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
1
by: MS Newsgroups | last post by:
Hi, I have managed to create a Datagrid with a template column with checkboxes following Q306227. The dataset i have bound to the datagrid contains 1 column that allows NULL value and I would...
0
by: mehul | last post by:
CheckBox template always evaluate to False even if checked in a DataGrid hosted inside a TabStrip in ASP.NET Hi, I am trying to develop an ASP.NET application. I am using TabStrip (which is...
7
by: Lars Netzel | last post by:
If I put a checkbox in a datagrid (ASP.NET) and set the Autopostback to true I can catch OnChange event on checkbox but how do I then catch what DataGridItemIndex is? Can I use some Event in the...
10
by: Jennyfer J Barco | last post by:
Hello, I have a datagrid that brings some information from a query. I need to have a checkbox in each row so the user can select the rows he wants to reprint. Is it possible to have a checkbox...
8
by: Alan Silver | last post by:
Hello, I have a repeater that has code like this... <ItemTemplate> <asp:CheckBox ID="chkDelete" Text="" RunAt="server"/> .... other stuff goes here </ItemTemplate> There is a button below...
0
by: emansc | last post by:
salamu alikom all, i inserted checkbox in a datagrid by using template column but in the run time, when i try to check any row & then click on a delete button,this row didn't deleted. i tried to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.