WebGrid Data

5 replies. Last post: March 15, 2016 9:55 AM by Erwin Sanders
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
John BoninMember

I'm trying to get to the underlying data of the webGrid in order to create a JSON string for use later.

I have no problem getting the column header names but can't get the value for each column for each row.

I'm using something like:

Public Shared Function GetWebJSONString(ByVal Dt As WebGrid) As String
            Dim count As Integer = Dt.RootTable.Columns.GetVisibleColumnsCount()
            Dim StrDc As String() = New String(count - 1) {}
            Dim HeadStr As String = String.Empty
            For i As Integer = 1 To count - 1
                StrDc(i) = Dt.RootTable.Columns(i).Name
                HeadStr += ("""" & StrDc(i) & """ : """) + StrDc(i) + i.ToString() & "¾" & ""","
            Next
            HeadStr = HeadStr.Substring(0, HeadStr.Length - 1)
            Dim Sb As New StringBuilder()
            For i As Integer = 0 To count - 1
                Dim TempStr As String = HeadStr
                Sb.Append("{")
                For j As Integer = 1 To Dt.RootTable.Rows.Count - 1
                    Dim zzzz As String = Dt.RootTable.Rows.GetItem(j).ToString
                    Dim zzzza As String = Dt.RootTable.GetUngrouppedRows().GetRowByKeyValue("2075246").Cells.GetNamedItem("CarrierName").Text.ToString()
                    'Dim rows As WebGridRowCollection = Dt.RootTable.GetUngrouppedRows()

                    'Dim keyValue As String = Dt.RootTable.GetUngrouppedRows().Item(j).KeyValue
                    'Dt.RootTable.GetUngrouppedRows().GetRowByKeyValue(keyValue).Cells.GetNamedItem("CarrierName").Text.ToString()
                    'Dim z As String = Dt.RootTable.GetUngrouppedRows().GetRowByKeyValue(keyValue).Cells.GetItem(j).ToString()
                    'TempStr = TempStr.Replace(Dt.RootTable.Columns(j).Name.ToString + j.ToString() & "¾", Dt.Rows(i)(j).ToString())
                Next
                Sb.Append(TempStr & "},")
            Next
            Sb = New StringBuilder(Sb.ToString().Substring(0, Sb.ToString().Length - 1))
            Return Sb.ToString()
        End Function

I've tried multiple ways to get the data but no seem to work! How can I get the following:

1. Total number of columns not just the visible columns

2. Get the keyValue of each row in the grid

3. The value for each column for each row in the grid

I need to get the data after the user has filtered and reduced the number of rows from the original query. This function runs froma Button click event.

Any help?

thanks



All times are GMT -5. The time now is 5:34 PM.
Previous Next