Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
Jacobus Visser via DotNetMonster.com #1
Datagrid Edit, Insert & Update Checkbox (ASP.NET Using VB.NET)
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("cbActi ve"), 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.Co unt = 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.Co unt =
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). _
Controls(1), TextBox).Text()
End If
End If
End If
Next
With Me.AquaDB
Try
.objDA_Profiles.Update(Me.DS_Profiles1)
Catch myerror As System.Data.NoNullAllowedException
Me.lblError.Text = "Could Not Update!"
End Try
End With
.SelectedIndex = -1
.EditItemIndex = -1
Me.Session("ssDSProfile") = Me.DS_Profiles1
.DataBind()
End With
Case "Cancel"
lblError.Text = ""
Me.masterDataGrid.SelectedIndex = -1
Me.masterDataGrid.EditItemIndex = -1
Me.DS_Profiles1.RejectChanges()
Me.Session("ssDSProfile") = Me.DS_Profiles1
Me.masterDataGrid.DataBind()
End Select
--
Message posted via [url]http://www.dotnetmonster.com[/url]
Jacobus Visser via DotNetMonster.com Guest
-
datagrid checkbox list edit item not working
I am using asp template columns. I display box values from a lookup table. The datagrid displays field "bookid" and the checkbox displays... -
Howto bind CheckBox to the datagrid/ Then update the database field when the checkbox is clicked.
I am trying to update the database field when the checkbox is clicked. I am trying to modified the following solution but.. got stuck on the... -
Datagrid checkbox value update issue
Hi, All, I am trying to bulid a web application for user's to approve certain information. On the web page, it shows a datagrid containing the... -
DataGrid with edit,insert & delete but with no ViewState !?
is this possible and how? -
To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible?
Hello, I am searching the whole Internet for a good example how to edit/update a DataGrid in a DataGrid (nested DataGrid). I know how to... -
Elton Wang #2
Datagrid Edit, Insert & Update Checkbox (ASP.NET Using VB.NET)
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
[email]elton_wang@hotmail.com[/email]
limited ASP>-----Original Message-----
>Hi you guys. If you could possible help me here.
>I am quite new to .NET coming over from VB and withthe fact that if I>development. I am having a problem with my checkbox inthe value from the>click edit on my datagrid the checkbox does not receiveno avail.>Database. I have tried several ways in doing this but toAnother Record">
>-----------------------
>Here is the code I use:
>-----------------------
>
>Select Case e.CommandName
> Case "Insert"
> If Me.masterDataGrid.EditItemIndex >= 0 Then
> lblError.Text = "Cannot Insert While Editing= ""> 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")("LastMedical") = Date.Now> Me.DS_Profiles1.Tables(0).NewRow.ItemTrue> Me.DS_Profiles1.Tables(0).NewRow.Item("Active") =Me.DS_Profiles1.Tables(0).NewRow> Dim rowNew As System.Data.DataRow =Me.masterDataGrid.Items.Count> Me.DS_Profiles1.Tables(0).Rows.Add(rowNew)
> Me.masterDataGrid.SelectedIndex =Me.masterDataGrid.Items.Count> Me.masterDataGrid.EditItemIndex =(masterDataGrid.SelectedIndex).Cells> Me.masterDataGrid.DataBind()
> Session("ssDSProfile") = DS_Profiles1
> Case "Edit"
> lblError.Text = ""
> Dim findval As Integer
> Dim checkval As String
> checkval = masterDataGrid.ItemsCheckBox)>(7).Text
> Me.masterDataGrid.EditItemIndex = e.Item.ItemIndex
> Me.masterDataGrid.DataBind()
> Dim cb As CheckBox = CType(masterDataGrid.Items
>(masterDataGrid.EditItemIndex).FindControl("cbAct ive"),(.EditItemIndex).FindControl("cbActive"),> 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(7).Controls(1), CheckBox)>CheckBox)
>
> If chkbox.Checked = True Then
> CType(.Items(.EditItemIndex).Cells(7).Controls(1), CheckBox)>..Checked = True
> Else
> CType(.Items(.EditItemIndex).Cells(.EditItemIndex).Cells.Count>..Checked = False
> End If ' set checkbox avtive
> Dim intcount As Integer
> For intcount = 1 To .Items(.EditItemIndex).Cells.Count Then> If intcount = .Items//////////////> Exit For
> End If
>'///////////////////////////////////////////////////////////////////////>'/// Check that control exists in this position
>'/////////////////////////////////////////////////////////= 1 Then>If .Items(.EditItemIndex).Cells(intcount).Controls.Co unt(.EditItemIndex).Cells(intcount)> If TypeOf (.Items(.EditItemIndex). _
> Cells(intcount). _
> Controls(0)) _
> Is TextBox Then
> If CType(.ItemsThen 'insert NULL if no data>..Controls(0), _
> TextBox).Text = ""4 Then> If intcount = 2 Or intcount =ALL REQUIRED> lblError.Text = "FILL INnot "">FIELDS"
> Exit Sub
> End If
>
> Else ' if(.EditItemIndex)> Me.DS_Profiles1.Tables(0).Rows(.EditItemIndex).Cells(intcount). _>..Item(.Columns(intcount).SortExpression) = _
> CType(.ItemsTextBox).Text()> Controls(0),(intcount).Controls.Count => End If
> End If
> End If
> If .Items(.EditItemIndex).Cells(.EditItemIndex).Cells(intcount)>3 Then
> If TypeOf (.Items(.EditItemIndex). _
> Cells(intcount). _
> Controls(1)) _
> Is TextBox Then
> If CType(.ItemsThen 'insert NULL if no data>..Controls(1), _
> TextBox).Text = ""4 Then> If intcount = 2 Or intcount =ALL REQUIRED> lblError.Text = "FILL INnot "">FIELDS"
> Exit Sub
> End If
> Else ' if(.EditItemIndex)> Me.DS_Profiles1.Tables(0).Rows(.EditItemIndex).Cells(intcount). _>..Item(.Columns(intcount).SortExpression) = _
> CType(.ItemsTextBox).Text()> Controls(1),(Me.DS_Profiles1)> End If
> End If
> End If
> Next
> With Me.AquaDB
> Try
> .objDA_Profiles.UpdateSystem.Data.NoNullAllowedException> Catch myerror As> Me.lblError.Text = "Could Not Update!"
> End Try
> End With
> .SelectedIndex = -1
> .EditItemIndex = -1
> Me.Session("ssDSProfile") = Me.DS_Profiles1
> .DataBind()
> End With
> Case "Cancel"
> lblError.Text = ""
> Me.masterDataGrid.SelectedIndex = -1
> Me.masterDataGrid.EditItemIndex = -1
> Me.DS_Profiles1.RejectChanges()
> Me.Session("ssDSProfile") = Me.DS_Profiles1
> Me.masterDataGrid.DataBind()
>End Select
>
>--
>Message posted via [url]http://www.dotnetmonster.com[/url]
>.
>Elton Wang Guest
-
Jacobus Visser via DotNetMonster.com #3
Re: Datagrid Edit, Insert & Update Checkbox (ASP.NET Using VB.NET)
Sorry forgot to remove the response code. I just inserted it into the code
to check what the values was before I posted the previous message.
--
Message posted via [url]http://www.dotnetmonster.com[/url]
Jacobus Visser via DotNetMonster.com Guest



Reply With Quote

