Question

I'm having trouble getting the column name in an autogenerated RadGridView on the ItemCommand. The problem is the columns are the result of a dynamic pivot table. Here's what my data looks like (SQL Server 2012):

Data before Pivot Data before Pivot

Data after Pivot enter image description here

So I'm taking the WorkWeek values, making them columns, and putting the WorkHours as the values in those columns.

The update command in my RadGridview would work as-is for a static table, but the pivot (and the resulting column name change) gums up the works. Here's the update command:

        For Each editedItem As GridEditableItem In RadGridViewExcelGridTest.EditItems
            Dim newValues As Hashtable = New Hashtable
            e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem)

            SqlDataSourceExcelGridTest.UpdateParameters.Clear()
            SqlDataSourceExcelGridTest.UpdateParameters.Add("DepartmentNumber", newValues("DepartmentNumber"))
            SqlDataSourceExcelGridTest.UpdateParameters.Add("ProjectNumber", newValues("ProjectNumber"))
            SqlDataSourceExcelGridTest.UpdateParameters.Add("Alias", newValues("Alias"))
            SqlDataSourceExcelGridTest.UpdateParameters.Add("WorkWeek", newValues("WorkWeek"))
            SqlDataSourceExcelGridTest.UpdateParameters.Add("WorkHours", newValues("WorkHours"))
            SqlDataSourceExcelGridTest.Update()

            editedItem.Edit = False
        Next

I checked my SQL Server Profiler, and I see that DepartmentNumber, ProjectNumber, and Alias values are being passed to my stored procedure correctly. However, WorkWeek and WorkHours pass NULLs. This is to be expected, since these columns don't exist in the grid. If I look at the keys/values in my hashtable, I see them in the format "2013-10-25 : 45" (for example). So instead of passing newValues("WorkWeek"), I need to pass the column's UniqueName, and use that with the WorkHours as well.

Any ideas on how to get the editied item's column's UniqueName?

Thanks!

Karl

Was it helpful?

Solution

In case anyone else runs into this, here's how this was solved:

    Dim columns As Array
        columns = RadGridViewExcelGridTest.MasterTableView.RenderColumns
        For Each editedItem As GridEditableItem In RadGridViewExcelGridTest.EditItems
            Dim newValues As Hashtable = New Hashtable
            For Each column As GridColumn In columns
                If (column.UniqueName <> "ExpandColumn" And column.UniqueName <> "RowIndicator" And column.UniqueName <> "DepartmentNumber" And column.UniqueName <> "ProjectNumber" And column.UniqueName <> "Alias" And column.UniqueName <> "Project" And column.UniqueName <> "Name") Then
                    e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem)

                    Dim columnValue As String = newValues(column.UniqueName)

                    SqlDataSourceExcelGridTest.UpdateParameters.Clear()
                    SqlDataSourceExcelGridTest.UpdateParameters.Add("DepartmentNumber", newValues("DepartmentNumber"))
                    SqlDataSourceExcelGridTest.UpdateParameters.Add("ProjectNumber", newValues("ProjectNumber"))
                    SqlDataSourceExcelGridTest.UpdateParameters.Add("Alias", newValues("Alias"))
                    SqlDataSourceExcelGridTest.UpdateParameters.Add("WorkWeek", column.UniqueName)
                    SqlDataSourceExcelGridTest.UpdateParameters.Add("WorkHours", columnValue)
                    SqlDataSourceExcelGridTest.Update()

                    editedItem.Edit = False
                End If
            Next

        Next

Credit goes to Angel Petrov, a Telerik admin.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top