Welcome Guest Search | Active Topics | Sign In | Register

Identify Column # of Grid When Updating Options
Yvette Meyer
Posted: Thursday, October 21, 2010 2:32:19 AM
Rank: Member
Groups: Member

Joined: 12/19/2007
Posts: 21
I have the following code working to update changes made in the Excel style format of the EO.Grid.

Dim vName As String
Dim vDocID As Int64
Dim s As String = String.Empty
If Grid1.ChangedItems.Length = 0 Then
s += "No item has changed."
Else

Dim item As EO.Web.GridItem
For Each item In Grid1.ChangedItems
Dim cell As EO.Web.GridCell
For Each cell In item.Cells

If cell.Modified Then
vName = cell.Value
vDocID = item.Key
SqlDataSource1.UpdateCommand = "UPDATE [tblPerfEvaluationSub] SET [Objective] = '" & vName & " ' WHERE [ID] = " & vDocID.ToString
SqlDataSource1.Update()
Dim [text] As String = String.Format("Cell Changed: Key = {0}, Field = {1}, New Value = {2}", item.Key, cell.Column.DataField, cell.Value)

s += "<br />"
s += [text]
End If
Next cell
Next item
End If

How can i identify the column of the cell that has changed to properly update the correct field in the database?
I have 7 columns in the grid that could possibly be changed so it appears I would need 7 update commands.
I hope I'm on the right track with my thinking.

Thank you.
Yvette Meyer
Posted: Thursday, October 21, 2010 3:09:46 AM
Rank: Member
Groups: Member

Joined: 12/19/2007
Posts: 21
I was able to identify the column name by using cell.Column.Name. Based on the column name I was able to generate an update statement.

I'd appreciate any feedback if this is the "wrong" way to go about identifying the column and updating the database.

Dim vName As String
Dim vColumn As String
Dim vDocID As Int64
Dim s As String = String.Empty
If Grid1.ChangedItems.Length = 0 Then
s += "No item has changed."
Else

Dim item As EO.Web.GridItem
For Each item In Grid1.ChangedItems
Dim cell As EO.Web.GridCell
For Each cell In item.Cells

If cell.Modified Then
vName = cell.Value
vColumn = cell.Column.Name
vDocID = item.Key
If vColumn = "chkDeactivate" Then
SqlDataSource1.UpdateCommand = "UPDATE [tblPerfEvaluationSub] SET [Active] = '" & vName & " ' WHERE [ID] = " & vDocID.ToString
SqlDataSource1.Update()
End If
If vColumn = "Objective" Then
SqlDataSource1.UpdateCommand = "UPDATE [tblPerfEvaluationSub] SET [Objective] = '" & vName & " ' WHERE [ID] = " & vDocID.ToString
SqlDataSource1.Update()
End If
If vColumn = "Outcome" Then
SqlDataSource1.UpdateCommand = "UPDATE [tblPerfEvaluationSub] SET [Outcome] = '" & vName & " ' WHERE [ID] = " & vDocID.ToString
SqlDataSource1.Update()
End If
If vColumn = "MgrResults" Then
SqlDataSource1.UpdateCommand = "UPDATE [tblPerfEvaluationSub] SET [Results] = '" & vName & " ' WHERE [ID] = " & vDocID.ToString
SqlDataSource1.Update()
End If
If vColumn = "Rating" Then
SqlDataSource1.UpdateCommand = "UPDATE [tblPerfEvaluationSub] SET [Rating] = '" & vName & " ' WHERE [ID] = " & vDocID.ToString
SqlDataSource1.Update()
End If
If vColumn = "EmplResults" Then
SqlDataSource1.UpdateCommand = "UPDATE [tblPerfEvaluationSub] SET [EmployeeResults] = '" & vName & " ' WHERE [ID] = " & vDocID.ToString
SqlDataSource1.Update()
End If
If vColumn = "EmplRating" Then
SqlDataSource1.UpdateCommand = "UPDATE [tblPerfEvaluationSub] SET [EmployeeRating] = '" & vName & " ' WHERE [ID] = " & vDocID.ToString
SqlDataSource1.Update()
End If

Dim [text] As String = String.Format("Cell Changed: Key = {0}, Field = {1}, New Value = {2}", item.Key, cell.Column.DataField, cell.Value)

s += "<br />"
s += [text]
End If
Next cell
Next item
End If
eo_support
Posted: Thursday, October 21, 2010 7:46:32 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

I believe your code is correct.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.