Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid value into Database?

Status
Not open for further replies.

gi11ies

Programmer
Mar 26, 2002
52
Hi

Im displaying a datalist with each row having an ID, name and a checkbox - what I want to do is if the checkbox is checked then insert the ID for that row into the database.

I can not get the value for inserting the ID for the selected row in the datagrid into the database.

The code I am using is as follows:

Dim dgItem as DataGridItem
Dim chkAdd as System.Web.UI.WebControls.CheckBox
Dim i as Integer
For i = ferDG.Items.Count-1 To 0 Step -1
chkAdd = CType(ferDG.Items(i).FindControl("itemCheck"), CheckBox)
If chkAdd.checked then
Dim ferMsgConn1 As OleDbConnection
Dim ferConn1 As String
ferConn1 = ConfigurationSettings.AppSettings("connString")
ferMsgConn1 = New OleDbConnection(ferConn1)
ferMsgConn1.Open
Dim ferSQL1 as String = "insert into recipients (message_id, to_id, status) values ('13', '" & CType(ferDG.Items(i).FindControl("uid"),String) & "', 'Pending')"'('" & Session("uid") & "','" & Session("fullname") & "','" & Session("location") & "','" & Session("location") & "')"
Dim ferCmd1 as New OleDbCommand(ferSQL1, ferMsgConn1)
ferCmd1.ExecuteNonQuery()
ferMsgConn1.Close
Response.Redirect("msgs_read.aspx")
End If
Next

The failing code is:

CType(ferDG.Items(i).FindControl("uid"),String)

Any tips on how to get this to work would be great.

Gillies
 
Make sure view state is enabled for the datagrid.

Try:

For each item as DataGridItem in ferDG.Items
If item.ItemType <> ListItemType.Header And item.ItemType <> ListItemType.Footer Then

if ctype(item.findcontrol("itemcheck"),checkbox).checked
'do stuff here
end if

end if
next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top