Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
255
Add a Column of Checkbox's in a UltraWebGrid
posted

I am trying to insert a invisible column into a UltraWebGrid that includeds a checkbox.  The purpose of the checkbox is to give each row a boolean value true if the row has a cell or cell's that have been edited and false if not.  Then have it loop through to pick up all rows that are true and update it back to the database.  I can't seem to find how to add a checkbox to the grid.  Open to all ideas, but prefer in Visual Basic do to the fact that is what I am working with.

Thanks in Advance

  • 45049
    Suggested Answer
    posted

    You can likely already get this from the grid already, by using its UpdateRow or UpdateRowBatch events.  These events are raised once for each row that was modified.  The difference between the events is that handling UpdateRow causes a postback to trigger when a row is modified, once that row or the grid loses focus, while UpdateRowBatch adds up all edits until something else triggers a postback.

    If you want to add a column to the grid to track this yourself anyway, you likely want to use an unbound boolean column.  Set the value of that cell to "true" to simulate a checked checkbox.  Consider the following VB.NET code added to the InitializeLayout event of the grid:

    Imports Infragistics.WebUI.UltraWebGrid
    ...
    Private Sub UltraWebGrid1_InitializeLayout(ByVal sender as Object, ByVal e as LayoutEventArgs) Handles UltraWebGrid1.InitializeLayout
        ' Create a new column - be sure that it's saved in ViewState
        Dim col as New UltraGridColumn(True)

        ' Set the column's Key so that you can refer to it again more easily
        col.Key = "HiddenBoolean"

        ' Make the column a boolean column
        col.DataType = GetType(System.Boolean).ToString()

        ' Hide the column
        col.Hidden = true

        ' Add the column to the root band of the grid
        e.Layout.Bands(0).Columns.Add(col)
    End Sub

  • 255
    posted

    Here is some uncomplete code:  A little buggy but it is what I am working with so if anyone needs a visual for a better idea

     Me.cn = New System.Data.SqlClient.SqlConnection

            Me.spNextBatchID = New System.Data.SqlClient.SqlCommand

            Me.spUpdate = New System.Data.SqlClient.SqlCommand

            Me.spRecalc = New System.Data.SqlClient.SqlCommand

     

     Me.spUpdate.CommandText = "[uspASR_AssetSchedule_Update]"

            Me.spUpdate.CommandType = System.Data.CommandType.StoredProcedure

            Me.spUpdate.Connection = Me.cn

            Me.spUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@inModifyReason", System.Data.SqlDbType.NVarChar, 250))

            Me.spUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@inLoanID", System.Data.SqlDbType.Decimal, 18, System.Data.ParameterDirection.Input, False, CType(18, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))

            Me.spUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@inMonthID", System.Data.SqlDbType.Decimal, 18, System.Data.ParameterDirection.Input, False, CType(18, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))

            Me.spUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@inYear", System.Data.SqlDbType.Decimal, 18, System.Data.ParameterDirection.Input, False, CType(18, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))

            Me.spUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@inMethodID", System.Data.SqlDbType.Decimal, 18, System.Data.ParameterDirection.Input, False, CType(18, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))

            Me.spUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@inAccountingRate", System.Data.SqlDbType.Decimal, 18, System.Data.ParameterDirection.Input, False, CType(18, Byte), CType(4, Byte), "", System.Data.DataRowVersion.Current, Nothing))

            Me.spUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@inBeginningBalance", System.Data.SqlDbType.Decimal, 18, System

     

        Private Const PrincipalQuery As String = _

            "SELECT " & vbCrLf & _

            "   loanID as 'Loan ID', [MonthID] as 'Month', [Year] as 'Year', MethodID as 'Method ID', " & vbCrLf & _

            "   Cast(AccountingRate as varchar(15)) + '%' as 'Accounting Rate', " & vbCrLf & _

            "   BeginningBalance as 'Beginning Balance', " & vbCrLf & _

            "   OriginalCost as 'Original Cost', " & vbCrLf & _

            "   Advances, Interest, " & vbCrLf & _

            "   GainLossOnPayoff as 'Gains/Loss On Payoff', " & vbCrLf & _

            "   Collections, Provisions, Recoveries, Adjustments, " & vbCrLf & _

            "   EndingBalance as 'Ending Balance', NPV, Difference, IRR, " & vbCrLf & _

            "   ModifyDate as 'Modified Date', ModifyBy as 'Last Modified By'" & vbCrLf & _

            "FROM acAssetSchedule " & vbCrLf & _

            "WHERE @LoanID In (-1, loanID)"

     

        Private Sub LoadGrid()

            'Dim ds As New DataSet

            'Dim da As New SqlClient.SqlDataAdapter

     

            'SQL Statement calls the loan id which doesn't exist and populates the initial grid with just headers

            ds.Tables.Add("TableGrid")

            da.SelectCommand = New SqlClient.SqlCommand(PrincipalQuery.Replace("@LoanID", "1"), Me.cn)

     

            da.Fill(ds.Tables("TableGrid"))

     

            Me.ugrdAScheduleMaint.DataSource = ds

            Me.ugrdAScheduleMaint.DataMember = "TableGrid"

     

            Me.DataBind()

            ConfigGrid()

        End Sub