DevExpress ASPxGridView
Post # 145 permalink Topic #145 by mreschke on 2009-05-18 13:22:58 (viewed 3,278 times)

Loop each grid row and get control[-][- -][++]

In this example, the GridView has 4 columns, a column with a checkbox, and 3 columns of data. I want to loop \
through all grid columns and get which checkboxes are selected. (Note the same column with the checkbox also \
has a hiddel ASPxLabel called lblID that holds the OPC_ID of the database row to be deleted). And in the \
GetCurrentPageRowValues("Confirm"), confirm is the header name (not caption, but name=) of a column in the grid (column display \
headers are 'Confirm,Op Code,Oldest History, RO Count')

Exclamation3
Note, the bind of this gv must be in Page_Load. When you click btnConfirm, Page_Load will bind gv again, but keep checkbox values, then btnConfirm will be called.

Code Snippet
    Protected Sub btnConfirm_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConfirm.Click
        Dim i As Int16 = 0
        Dim chk As DevExpress.Web.ASPxEditors.ASPxCheckBox
        Dim lblID As DevExpress.Web.ASPxEditors.ASPxLabel
        For i = 0 To grdConfirm.GetCurrentPageRowValues("Confirm").Count - 1
            chk = grdConfirm.FindRowCellTemplateControl(i, grdConfirm.Columns(0), "chkDelete")
            If chk.Checked Then
                lblID = grdConfirm.FindRowCellTemplateControl(i, grdConfirm.Columns(0), "lblID")
                'lblError.Text &= lblID.Text.ToString & ","
                DAL.OpcHistory.DelSelection(Val(ddlCategory.Value.ToString), Me.DLR_ID, lblID.Text)
            End If
        Next
        pnlConfirm.Visible = False
        pnlOptions.Visible = True
        txtFilter.Text = ""
        Me.FillListBoxes()
    End Sub

Hide Grid inside Main Grids Edit Template[-][- -][++]

Hide the grid on control click[-][- -][++]

I have 2 grids, one is inside the others edit template, I want to hide the second grid with a client side click.

Note, the ASPxRadioButton, or all ASPx controls don't have a standard onclick, so I surrounded it with a div

This is just a nice example of finding the element id of a burried grid with javascript
somecode.aspx

Code Snippet
...
<div onclick="document.getElementById('<%= gvPerms.FindEditFormTemplateControl("gvCustomPerms").ClientID %>').style.display='none';"><dxe:ASPxRadioButton ID="radNothing" ClientInstanceName="radNothing" GroupName="perm" Checked="true" runat="server"></dxe:ASPxRadioButton></div>
...
<dxwgv:ASPxGridView ID="gvCustomPerms" ClientInstanceName="gvCustomPerms">
...

Hide the grid initially[-][- -][++]

This is a beauty, when they click edit on the master grid, I want the second grid to be clientside display:none or block \
depending on a value in the master grids database column.

So if the database column value is > 0 then I should display the second grid. So I wrote a codebehind vb function

Code Snippet
    Public Function test(ByVal value As Integer) As String
        If value > 0 Then Return "block" Else Return "none"

    End Function

Then in the .aspx page, I set a variable style parameter

Code Snippet
<asp:Panel ID="gvCustomPermsDiv" runat="server" style='<%# "display:" & test(Eval("Limit")) & ";" %>'>
<b>Select the Custom Page Permission for this group</b>
<dxwgv:ASPxGridView ID="gvCustomPerms" ClientInstanceName="gvCustomPerms" OnDataBinding="gvCustomPerms_DataBinding">
...

So the Eval("Limit") sets the radLimit radio button above, so it radLimit is checked (So Eval(Limit) > 0) then \
show the grid initially, else hide it. Nice!

You can even skip the codebehind function creation and simply use the build in function IIF, this is a better solution.

Code Snippet
<asp:Panel ID="gvCustomPermsDiv" runat="server" style='<%# "display:" & iif(Eval("Limit")>0,"block","none") %>'>