Datagrid with Checkboxes

D

dave

I have a datagrid with checkboxes for each row.

The user is able to select the ones he wants, then hit a "Save" button,
which then loops through them all and insert the checked ones into a DB.

At the moment i am using the following code to do it, which is assigning the
ID of the record to the "text" value of the checkbox, then i am using this
to insert the correct records into the DB.

My question is: - is it possible to do this using the Datakeyfield value,
which is also set in the dgrid to record ID for each row - as my solution is
not ideal, as the user can see the ID's assigned to the checkbox text if
they highlight the grid/page. I have come across some articles which use the
hidden column method...

Any pointer/code examples would be much appreciated....

Cheers


'///////////////////////////////////////////////////////////////////////////
////////////
Sub InsertAssigned()
Dim GridItem As System.Web.UI.WebControls.DataGridItem
Dim chkBox as System.Web.UI.WebControls.CheckBox
Dim SQLUpdate as String

For Each GridItem In dgBrowser.Items
chkBox = GridItem.FindControl("SELECTED_ITEMS")
If chkBox.Checked Then
SQLUpdate = "INSERT INTO dbo.COURSE_GROUPS_LIST ( COURSE_GROUP_ID,
COURSE_ROOT_ID, "
SQLUpdate = SQLUpdate & "ADDED_BY_USER_ID, LICENSE_ID ) "
SQLUpdate = SQLUpdate & "VALUES "
SQLUpdate = SQLUpdate & "( " & "" & SelectedID & ", "
SQLUpdate = SQLUpdate & "'" & System.Convert.ToInt32(chkBox.Text) & "', "
SQLUpdate = SQLUpdate & "'" & Session("USER_ID") & "', "
SQLUpdate = SQLUpdate & "'" & Session("LICENSE_ID") & "' ) "

MiscFunctions.SQLNonQuery( SQLUpdate )
End If
Next
End Sub
 
T

Trevor Benedict R

You can still use this method. Alternately you can have a hidden column
and do not pass the id as a value to the checkbox. Then during the save
method instead of using the value from the Checkbox you can use it from
the hidden column if the particular checkbox is checked.

HTH

Trevor Benedict R
MCSD

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top