Datagrid Edit, Insert & Update Checkbox (ASP.NET Using VB.NET)


E

Elton Wang

Hi

Don't use Response.End() before you finish all execution
code. Response.End() means stop server execution and send
response content to client immediately. Hence any code
after it will nerver be executed.

HTH

Elton Wang
(e-mail address removed)
-----Original Message-----
Hi you guys. If you could possible help me here.
I am quite new to .NET coming over from VB and with limited ASP
development. I am having a problem with my checkbox in the fact that if I
click edit on my datagrid the checkbox does not receive the value from the
Database. I have tried several ways in doing this but to no avail.

-----------------------
Here is the code I use:
-----------------------

Select Case e.CommandName
Case "Insert"
If Me.masterDataGrid.EditItemIndex >= 0 Then
lblError.Text = "Cannot Insert While Editing Another Record"
Exit Sub
End If
lblError.Text = ""
' Add data to the row.
' Add the new row to the table.
Me.DS_Profiles1.Tables(0).NewRow.Item("Name") = ""
Me.DS_Profiles1.Tables(0).NewRow.Item("Phone") = ""
Me.DS_Profiles1.Tables(0).NewRow.Item("Cell") = ""
Me.DS_Profiles1.Tables(0).NewRow.Item("Email") = ""
Me.DS_Profiles1.Tables(0).NewRow.Item("IDnumber") = ""
Me.DS_Profiles1.Tables(0).NewRow.Item ("LastMedical") = Date.Now
Me.DS_Profiles1.Tables(0).NewRow.Item("Active") = True
Dim rowNew As System.Data.DataRow = Me.DS_Profiles1.Tables(0).NewRow
Me.DS_Profiles1.Tables(0).Rows.Add(rowNew)
Me.masterDataGrid.SelectedIndex = Me.masterDataGrid.Items.Count
Me.masterDataGrid.EditItemIndex = Me.masterDataGrid.Items.Count
Me.masterDataGrid.DataBind()
Session("ssDSProfile") = DS_Profiles1
Case "Edit"
lblError.Text = ""
Dim findval As Integer
Dim checkval As String
checkval = masterDataGrid.Items (masterDataGrid.SelectedIndex).Cells
(7).Text
Me.masterDataGrid.EditItemIndex = e.Item.ItemIndex
Me.masterDataGrid.DataBind()
Dim cb As CheckBox = CType(masterDataGrid.Items
(masterDataGrid.EditItemIndex).FindControl("cbActive"), CheckBox)
Response.Write(checkval)
Response.End()
If checkval = "True" Then
cb.Checked = True
Else
cb.Checked = False
End If

Case "Update"
With masterDataGrid
Dim chkbox As New CheckBox
chkbox = CType(.Items (.EditItemIndex).FindControl("cbActive"),
CheckBox)

If chkbox.Checked = True Then
CType(.Items(.EditItemIndex).Cells (7).Controls(1), CheckBox)
..Checked = True
Else
CType(.Items(.EditItemIndex).Cells (7).Controls(1), CheckBox)
..Checked = False
End If ' set checkbox avtive
Dim intcount As Integer
For intcount = 1 To .Items (.EditItemIndex).Cells.Count
If intcount = .Items
(.EditItemIndex).Cells.Count Then
Exit For
End If
'///////////////////////////////////////////////////////// //////////////
'/// Check that control exists in this position
'///////////////////////////////////////////////////////// //////////////
If .Items(.EditItemIndex).Cells(intcount).Controls.Count = 1 Then
If TypeOf (.Items(.EditItemIndex). _
Cells(intcount). _
Controls(0)) _
Is TextBox Then
If CType(.Items (.EditItemIndex).Cells(intcount)
..Controls(0), _
TextBox).Text = "" Then 'insert NULL if no data
If intcount = 2 Or intcount = 4 Then
lblError.Text = "FILL IN ALL REQUIRED
FIELDS"
Exit Sub
End If

Else ' if not ""
Me.DS_Profiles1.Tables(0).Rows (.EditItemIndex)
..Item(.Columns(intcount).SortExpression) = _
CType(.Items
(.EditItemIndex).Cells(intcount). _
Controls(0), TextBox).Text()
End If
End If
End If
If .Items(.EditItemIndex).Cells (intcount).Controls.Count =
3 Then
If TypeOf (.Items(.EditItemIndex). _
Cells(intcount). _
Controls(1)) _
Is TextBox Then
If CType(.Items (.EditItemIndex).Cells(intcount)
..Controls(1), _
TextBox).Text = "" Then 'insert NULL if no data
If intcount = 2 Or intcount = 4 Then
lblError.Text = "FILL IN ALL REQUIRED
FIELDS"
Exit Sub
End If
Else ' if not ""
Me.DS_Profiles1.Tables(0).Rows (.EditItemIndex)
..Item(.Columns(intcount).SortExpression) = _
CType(.Items
(.EditItemIndex).Cells(intcount). _
 
Ad

Advertisements


Top