User Profile & Activity

Daniel Carriere Member

Hello and thank you for your prompt response. I played around with some of the WebGrid's properties and fixed the issue. I'm not sure which one did it, but it is fixed. Unfortunately, I am now having another issue.

This project was very difficult to build because of the nature of the table used for the Datasource. The columns are different depending on the user. One user may have 5 columns, while the next could have 7 or 9 (increments in 2). This is dependent on the number of positions they have within the company, so I couldn't simply create columns in the grid and create the datasource straight from the source. What I did was create a Webservice that compiles the information and returns a dataset with a table called "GRID". Here is the code I use to set the datasource:

Protected Sub WebGrid1_InitializeDataSource(ByVal sender As Object, ByVal e As ISNet.WebUI.WebGrid.DataSourceEventArgs) Handles WebGrid1.InitializeDataSource
    Dim SH As New WebServ.Service
    Dim DS As Data.DataSet = SH.ReturnTimecardInfo(Session("UserName"), Session("Password"))
    Dim AddTot As Data.DataColumn = New Data.DataColumn("TOTAL")
    AddTot.DataType = System.Type.GetType("System.Double")DS.Tables("GRID").Columns.Add(AddTot)
    Dim RCount As Integer = 0
    Dim RFind As Data.DataRow
    Dim Fin As Boolean = False

    Do Until RCount = DS.Tables("GRID").Rows.Count
        RFind = DS.Tables("GRID").Rows(RCount)

        If RFind.Item("Finalized") = "TRUE" Then
            Then Fin = True
        End If

        RCount += 1
    Loop

    If Fin = True Then
        Then Label17.Text = "STATUS: SENT TO SUPERVISOR"
        WebGrid1.Enabled = False
        Button1.Visible = False
    Else : Label17.Text = "STATUS: OPEN"
        WebGrid1.Enabled = True
        Button1.Visible = True
    End If

    e.DataSource = DS
End Sub

That works just fine, the data displays in the grid. I then set up the first two columns as well as the last column to NoEdit and populate a dropdown for each second column between the first two and the last columns. Here is the code:

Protected Sub WebGrid1_PrepareDataBinding(ByVal sender As Object, ByVal e As ISNet.WebUI.WebGrid.DataSourceEventArgs) Handles WebGrid1.PrepareDataBinding
    If (Not IsPostBack) Then
        WebGrid1.RetrieveStructure()
        WebGrid1.RootTable.DataKeyField = "WORKDATE"
        WebGrid1.RootTable.Columns(0).EditType = ISNet.WebUI.WebGrid.EditType.NoEdit
        WebGrid1.RootTable.Columns(0).Caption = "Date"
        WebGrid1.RootTable.Columns(1).EditType = ISNet.WebUI.WebGrid.EditType.NoEdit
        WebGrid1.RootTable.Columns(1).Caption = "Day"

        Dim ColCount As Integer = 2

        Do Until ColCount = WebGrid1.RootTable.Columns.Count - 2
            Dim EARNDED As String = WebGrid1.RootTable.Columns(ColCount).Name
            Dim GetED() As Data.DataRow = DS.Tables("EARNDED").Select("EARNDED = '" & EARNDED & "'")

            If GetED.GetLength(0) <> 0 Then
                Dim SH As New WebServ.Service
                Dim DT As Data.DataTable = SH.GetManagers(Session("UserName"), Session("Password"), EARNDED)

                WebGrid1.RootTable.Columns(ColCount).Caption = EARNDED & vbCrLf & GetED(0).Item("EARNDEDNAME")
                WebGrid1.RootTable.Columns(ColCount + 1).Caption = "SUPERVISOR"
                WebGrid1.RootTable.Columns(ColCount).AggregateFunction = AggregateFunctions.Sum
                WebGrid1.RootTable.Columns(ColCount + 1).EditType = EditType.DropdownList

                Dim vl As WebValueList = WebGrid1.RootTable.Columns(ColCount + 1).ValueList

                vl.DataSource = DT
                vl.DataTextField = "ManagerName"
                vl.DataValueField = "ManagerName"
            End If

            ColCount += 1
        Loop

        WebGrid1.RootTable.Columns.GetNamedItem("TOTAL").EditType = ISNet.WebUI.WebGrid.EditType.NoEdit
        WebGrid1.RootTable.Columns.GetNamedItem("TOTAL").Caption = "TOTAL"
        WebGrid1.RootTable.Columns.GetNamedItem("TOTAL").AggregateFunction = AggregateFunctions.Custom
        WebGrid1.RootTable.Columns.GetNamedItem("Finalized").Visible = False

    End If
End Sub

This also works just fine on initial loading of the page.  When the user fills in row information and leaves the row, the grid sends that row's information back to the Webservice, which updates the database:

Protected Sub WebGrid1_UpdateRow(ByVal sender As Object, ByVal e As ISNet.WebUI.WebGrid.RowEventArgs) Handles
    WebGrid1.UpdateRowe.ReturnValue = True

    Dim HeaderString As String = ""
    Dim DetailString As String = ""
    Dim ColCount As Integer = 2

    Do Until ColCount = WebGrid1.RootTable.Columns.Count - 2
        If HeaderString = "" Then
            HeaderString = e.Row.Cells(ColCount).Column.Name

        Else : HeaderString &= "~~" & e.Row.Cells(ColCount).Column.Name
        End If

        If Microsoft.VisualBasic.Right(e.Row.Cells(ColCount).Column.Name, 2) = "CC" Then
            If DetailString = "" Then
                DetailString = CStr(e.Row.Cells(ColCount).Text)
            Else : DetailString &= "~~" & CStr(e.Row.Cells(ColCount).Text)
            End If
        ElseIf DetailString = "" Then
            DetailString = CStr(e.Row.Cells(ColCount).Text)
        Else : DetailString &= "~~" & CStr(e.Row.Cells(ColCount).Text)
        End If

        ColCount += 1
    Loop

    Dim SH As New WebServ.Service
    Dim SHYN As Boolean = SH.UpdateTimecardInfo(Label11.Text, Label12.Text, Label10.Text, e.Row.Cells(0).Text, HeaderString, DetailString)

    e.ReturnValue = True
End Sub

This also works, but, after the update, if there is a horizontal scrollbar in the grid, the last column becomes editable and sometimes (not always), the column values and dropdowns shift over one column and the last column becomes the dropdown from the column before it. Oddly enough, the issue is resolved when the user scrolls back to the beginning of the grid.

Here is my code for OnAfterUpdate:

<script language="javascript" type="text/javascript">
    <!--
    function WebGrid1_OnAfterUpdate(controlId, tblName, rowObject, xmlResponseObject)
    {
        var WebGrid1 = ISGetObject(controlId); var selRow = WebGrid1.GetSelectedObject().GetRowElement(); var selObj = webgrid1.getselectedobject();
        selRow.AddPendingChanges;

        selRow.AcceptChanges;

        return true;
    }
    -->
</script>

Any idea as to what the problem could be?  If necessary, I can send you the URL for the test website with proper credentials and you can give it a try.

Thank you,

Dan

All times are GMT -5. The time now is 11:41 AM.
Previous Next