How to do a multiple select and update in a datagrid

W

Wolffang

Using Visual studio.net VB

I have a datagrid that brings records from a stored procedure.

Be selecting multiple datarows using a checkbox.
All i want to do is update a field called 'Active' datatype bit from 0 to 1
for all those records that have been selected with the checkbox and mark
another field 'User' with the name of the user who selected these items when
a update button is clicked.

checkbox needs to be disabled if the record of 'Active' is 1

any solutions out there???
 
I

irene

You can do a batch update.
something like:

Dim dg As DataGridItem
Dim ck As CheckBox
Dim UserID As Label

For Each dg In yourdatagrid.Items
ck = dg.FindControl("yourcheckboxname")
UserID = dg.FindControl("yourdatakeyfield")

If ck.Checked = True Then
UpdateUserHistory(UserID.Text, 1)
Else
UpdateUserHistory(UserID.Text, 0)
End If

Next

and then you can define the function on UpdateUserHistory...


HTH,

Irene
 
W

Wolffang

Thank you for your answer...

This is what i have so far.... but i am geting an error.... where the OrderID is not being passed from the datagrid "dgOrders" to the stored procedure... but the checkbox is working... is this because i am using FindControl???

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim dg As DataGridItem

Dim ck As CheckBox

Dim OrdID As Label

Me.SqlConnection1.Open()

For Each dg In dgOrders.Items

ck = dg.FindControl("chkSelect")

OrdID = dg.FindControl("OrderID")



If ck.Checked = True Then

Me.SqlCommand1.Parameters("@OrderID").Value = OrdID

Me.SqlCommand1.Parameters("@AdminUserName").Value = lblUserName.Text

Me.SqlCommand1.Parameters("@AdminProcess").Value = 1

Me.SqlCommand1.ExecuteNonQuery()

End If

Next

Me.SqlConnection1.Close()

End Sub
 

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,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top