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
470
How to programmatically check/uncheck all checkboxes in a column added at runtime
posted

I have an UltrawebGrid that I programmatically add a column to at runtime upon a button click..

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnEnableCopy.Click

Me.DIV_CopyControls.Visible = True

If Me.UltraWebGrid_Segment.Columns.FromKey("Select") Is Nothing Then

Me.UltraWebGrid_Segment.Columns.Insert(0, "Select")

Me.UltraWebGrid_Segment.Columns.FromKey("Select").Type = Infragistics.WebUI.UltraWebGrid.ColumnType.CheckBox

Me.UltraWebGrid_Segment.Columns.FromKey("Select").Header.Caption = "Select"

Me.UltraWebGrid_Segment.Columns.FromKey("Select").Hidden = False

Me.UltraWebGrid_Segment.Columns.FromKey("Select").Width = System.Web.UI.WebControls.Unit.Pixel(50)

'Me.UltraWebGrid_Segment.DataBind()

End If

Me.BtnEnableCopy.Visible = False

End Sub

The column appears and I can check/uncheck as needed. I can then click a button that scans through the rows acting based on the state of the 'select' checkbox.

...

For Each ThisRow As Infragistics.WebUI.UltraWebGrid.UltraGridRow In Me.UltraWebGrid_Segment.Rows

If ThisRow.Cells.FromKey("Select").Value = True Then

thisSQLCommand.Parameters.Clear()

thisSQLCommand.Parameters.AddWithValue("Parcel_ID", ThisRow.Cells.FromKey("Parcel_ID").Value.ToString)

thisSQLCommand.Parameters.AddWithValue("Old_Segment_ID", Me.DDL_segment_area.SelectedValue.ToString)

thisSQLCommand.Parameters.AddWithValue("New_Segment_ID", Me.DDL_SegmentsCopy.SelectedValue.ToString)

Try

thisSQLCommand.ExecuteNonQuery()

Catch ex As Exception

ErrorInfo = "Allotment: " + ThisRow.Cells.FromKey("Allotment").Value.ToString + " failed to copy. It probably already exists in the target segment."

ErrorInfo = ErrorInfo + System.Environment.NewLine

Me.txtErrorMessage.Text = Me.txtErrorMessage.Text + ErrorInfo

Me.DIV_Errors.Visible = True

End Try

End If

Next

...

Again this works fine.

What I am trying to accomplish now is to have buttons to select all or unselect all checkboxes in the 'select' column.

What I've tried is..

Protected Sub btnSelectAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSelectAll.Click

For Each thisRow As Infragistics.WebUI.UltraWebGrid.UltraGridRow In UltraWebGrid_Segment.Rows()

thisRow.Cells.FromKey("Select").Value = True

Next

End Sub

Visually this selects all the checkboxes in the column and looks good.

The problem is when I click on my button to process the grid all of the checkboxes are now unchecked - something is causing me to lose the values.

I only lose the state of the checkboxes when I programmatically set them (through a postback which I assume is the issue). The state is correct if I just manually check/uncheck checkboxes and then click the 'process' button.

What do I I need to do to make a 'select all' and 'select none' button work for this? Do I need to do it on the client side (if so please give me a some clear code to do it - javascript is my enemy)...

I tried to submit this as a priority support request twice today - keep getting an error on the page after I click submit :(