This is a migrated thread and some comments may be shown as answers.

Check\Uncheck All Hierarchy Grid

4 Answers 129 Views
Grid
This is a migrated thread and some comments may be shown as answers.
codispdp
Top achievements
Rank 1
codispdp asked on 16 Oct 2008, 08:43 PM
I am having a problem exposing the detail table in a hierarchy grid for a check\uncheck all with a header checkbox. Does anyone have a working example of independant tables (Master and Detail) check\check all?


Protected Sub DetailToggleSelectedState(ByVal sender As ObjectByVal e As EventArgs)  
        If (CType(sender, CheckBox)).Checked Then 
            For Each dataItem As GridDataItem In rgProjects.MasterTableView.DetailTables(0).Items  
                CType(dataItem.FindControl("DetailCheckBox"), CheckBox).Checked = True 
                dataItem.Selected = True 
            Next 
        Else 
            For Each dataItem As GridDataItem In rgProjects.MasterTableView.DetailTables(0).Items  
                CType(dataItem.FindControl("DetailCheckBox"), CheckBox).Checked = False 
                dataItem.Selected = False 
            Next 
        End If 
    End Sub 

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Oct 2008, 04:14 AM
Hi,

Try using  a GridClientSelectColumn in the detail table to achieve the desired scenario.

ASPX:
 <DetailTables> 
    <telerik:GridTableView runat="server"  EditMode="InPlace"   CommandItemDisplay="Top" Name="Detail1" DataSourceID="SqlDataSource1" > 
      <Columns>   
           <telerik:GridClientSelectColumn></telerik:GridClientSelectColumn> 
            ........... 

 <ClientSettings    > 
   <Selecting  AllowRowSelect="True" /> 
  </ClientSettings> 

You can also refer the following demo link
Several tables at a level

Thanks
Shinu
0
codispdp
Top achievements
Rank 1
answered on 17 Oct 2008, 03:05 PM
Shinu,

Thanks for you suggestion, it works well. How can I maintain the selections in the child records after expand and collapse postback?
0
Shinu
Top achievements
Rank 2
answered on 20 Oct 2008, 05:25 AM
Hi,

Here is a code library submission which explains how to retain selected state in a Hierarchical Grid on rebind. Go through it and see if it helps.
Retain expanded/selected state in hierarchy on rebind

Thanks
Shinu.
0
codispdp
Top achievements
Rank 1
answered on 20 Oct 2008, 11:26 AM
I have tried your suggestion but it does not work using the DetailTableDataBind event of the RadGrid. Here is what I have so far, a button to conduct a search for that will populate a DataTable for the grid and I am using the DetailTableDataBind to populate the child record. I have also added code to maintain the selected items in the detail table, but when I try to collapse the row it will not and I lose the first child selected for that record.

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server">  
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server">  
    <div> 
    <ajax:ScriptManager ID="ScriptManager1" runat="server" /> 
 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="rgProjects">  
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="rgProjects" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
    </telerik:RadAjaxManager> 
 
<table cellspacing="0" cellpadding="3" width="95%" border="0">  
<tr> 
<td> 
<table cellspacing="0" cellpadding="3" width="95%" border="0">  
  <tr> 
      <td class="StdText" align="center">  
          Project Number  
      </td> 
      <td class="StdText" align="center">  
          Profile Number  
      </td> 
      <td align="center" rowspan="2">  
          <asp:Button ID="Search_btn" runat="server" Width="120px" Text="Get Record(s)" SkinID="StandardButton" Height="45px" /> 
      </td> 
  </tr> 
  <tr> 
<td align="center">  
 
<telerik:RadGrid  
ID="rgProjects" 
runat="server" 
Skin="Office2007" 
Width="95%" 
CellPadding="1" 
CellSpacing="0" 
PageSize="100" 
AllowPaging="True" 
AllowSorting="True" 
ShowStatusBar="true" 
AllowMultiRowSelection="True" 
AutoGenerateColumns="False">  
<PagerStyle Mode="NumericPages"></PagerStyle> 
<MasterTableView Width="100%" DataKeyNames="Profile_Num" AllowMultiColumnSorting="True" Name=ProjectProfile>  
 
<Columns> 
<telerik:GridClientSelectColumn Reorderable=true UniqueName="ClientSelectColumnMaster" /> 
<telerik:GridBoundColumn SortExpression="PROJECT_NUMBER" HeaderText="Project" HeaderButtonType="TextButton" DataField="PROJECT_NUMBER" /> 
<telerik:GridBoundColumn SortExpression="PROFILE_NUM" HeaderText="Profile" HeaderButtonType="TextButton" DataField="PROFILE_NUM" /> 
<telerik:GridBoundColumn SortExpression="LOGO" HeaderText="Logo" HeaderButtonType="TextButton" DataField="LOGO" /> 
<telerik:GridBoundColumn SortExpression="COORDINATOR_NAME" HeaderText="Coord" HeaderButtonType="TextButton" DataField="COORDINATOR_NAME" /> 
<telerik:GridBoundColumn SortExpression="DESCRIPTION" HeaderText="Profile Description" HeaderButtonType="TextButton" DataField="DESCRIPTION" /> 
<telerik:GridBoundColumn SortExpression="REGION_DESC" HeaderText="Region" HeaderButtonType="TextButton" DataField="REGION_DESC" /> 
<telerik:GridBoundColumn SortExpression="CREATOR" HeaderText="Created By" HeaderButtonType="TextButton" DataField="CREATOR" /> 
</Columns> 
 
<DetailTables> 
<telerik:GridTableView DataKeyNames="TASK_NUMBER" Name="Tasks" Width="100%">  
<Columns> 
<telerik:GridClientSelectColumn Reorderable=true UniqueName="ClientSelectColumnDetail" /> 
<telerik:GridBoundColumn DataField="TASK_DESCRIPTION_B" HeaderText="Task Description" HeaderButtonType="TextButton" /> 
<telerik:GridBoundColumn DataField="GROUP_ASSIGNED" HeaderText="Grp" HeaderButtonType="TextButton" /> 
<telerik:GridBoundColumn DataField="COMPLETED_FLAG" HeaderText="Cmp" HeaderButtonType="TextButton" /> 
telerik:GridBoundColumn DataField="USER_COMPLETED" HeaderText="User Completed" HeaderButtonType="TextButton" /> 
<telerik:GridBoundColumn DataField="DATE_COMPLETED" HeaderText="Date Completed" HeaderButtonType="TextButton" /> 
<telerik:GridBoundColumn DataField="ACTIVE_FLAG" HeaderText="Act" HeaderButtonType="TextButton" /> 
<telerik:GridBoundColumn DataField="DATE_ACTIVATED" HeaderText="Date Activated" HeaderButtonType="TextButton" /> 
<telerik:GridBoundColumn DataField="TASK_NUMBER" HeaderText="Task#" HeaderButtonType="TextButton" /> 
<telerik:GridBoundColumn DataField="DATE_CREATED" HeaderText="Date Created" HeaderButtonType="TextButton" /> 
</Columns> 
</telerik:GridTableView> 
</DetailTables> 
 
</MasterTableView> 
<ClientSettings EnablePostBackOnRowClick="true" > 
<Selecting AllowRowSelect="true" /> 
</ClientSettings> 
</telerik:RadGrid> 
   </td> 
</tr> 
</table> 
</td> 
</tr> 
</table> 
</div> 
</form> 
</body> 
</html> 



Imports System  
Imports System.Text  
Imports Telerik.Web.UI  
Imports System.Data.OracleClient  
 
Partial Class Nala_Maintenance  
    Inherits System.Web.UI.Page  
 
   Private _ordersExpandedState As Hashtable  
   Private _selectedState As Hashtable  
 
Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
        Dim i As Integer 
 
If Not Page.IsPostBack Then 
 Session("selectedItems") = Nothing 
 
txtConnectionString.Text = eworkdev.Utilities.GetRegistryValue("Software\FiservEFT\SIMBBA""ConnectionString", eworkdev.Utilities.RegistryRoot.LocalMachine) & "User Id=" & Session.Contents("UserID") & ";Password=" & Session.Contents("Password") & ";" 
        End If 
    End Sub 
 
 Private Sub Search_btn_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Search_btn.Click  
        Session("selectedItems") = Nothing 
        BindMaster()  
    End Sub 
 
Sub BindMaster()  
 
        Dim szFilter As String 
        Dim nWhere As Boolean 
        Dim szOperator As String 
        Dim strOrderBy As String 
      
   If lblMessage.Visible Then 
            lblMessage.Visible = False 
        End If 
 
        szFilter = "" 
        strOrderBy = " ORDER BY PROJECT_NUMBER, PROFILE_NUM " 
 
        If (txtProject_Number.Text <> ""Then 
            nWhere = True 
            szOperator = " = " 
            szFilter = "PROJECT_NUMBER" & szOperator & txtProject_Number.Text  
        End If 
 
        If (txtProfile_Number.Text <> ""Then 
            If nWhere Then 
                szFilter = szFilter & " AND " 
            Else 
                nWhere = True 
            End If 
            szOperator = " = " 
            szFilter = szFilter & "PROFILE_NUM" & szOperator & txtProfile_Number.Text  
        End If 
 
        If szFilter = "" Then 
            szFilter = "True" 
        End If 
 
        ProjectFilterValue = "SELECT PROJECT_NUMBER, PROFILE_NUM, LOGO, COORDINATOR_NAME, " & _  
                                    "DESCRIPTION, 'NA' REGION_DESC,CREATOR FROM " & _  
                                    "SIMBBA.V_WEB_PROJECT_INFO_V60 WHERE " & szFilter & strOrderBy  
 
        Dim dataTable As DataTable = GetDataTable(ProjectFilterValue)  
        rgProjects.DataSource = dataTable  
        rgProjects.DataBind()  
 
        nWhere = False 
 
        If txtProfile_Number.Text <> "" Then 
 
            If dataTable.Rows.Count = 1 Then 
                'Fist column Project_number is in dataTable.Rows.Item(0).Item(0)  
                'Second column Profile_num is in dataTable.Rows.Item(0).Item(1)  
                Dim intProjectNumber As String = dataTable.Rows.Item(0).Item(0)  
                Dim intProfielNumber As String = dataTable.Rows.Item(0).Item(1)  
 
                Dim strRecordDetailSQL As String = "SELECT C.PROFILE_COUNT, NVL(A.CLOSED_TASKS,0) CLOSED_TASKS, NVL(B.OPEN_TASKS,0) OPEN_TASKS " & _  
                                                                " FROM " & _  
                                                                "(SELECT COUNT(TASK_NUMBER) CLOSED_TASKS " & _  
                                                                ", PROJECT_NUMBER " & _  
                                                                ", PROFILE_NUM " & _  
                                                                "FROM SIMBBA.TASKS " & _  
                                                                "WHERE PROFILE_NUM = " & intProfielNumber & " " & _  
                                                                "AND COMPLETED_FLAG='Y' " & _  
                                                                "GROUP BY PROJECT_NUMBER, PROFILE_NUM) A " & _  
                                                                ",(SELECT COUNT(TASK_NUMBER) OPEN_TASKS " & _  
                                                                ", PROJECT_NUMBER " & _  
                                                                ", PROFILE_NUM " & _  
                                                                "FROM SIMBBA.TASKS " & _  
                                                                "WHERE PROFILE_NUM = " & intProfielNumber & " " & _  
                                                                "AND COMPLETED_FLAG='N' " & _  
                                                                "GROUP BY PROJECT_NUMBER, PROFILE_NUM) B " & _  
                                                                ",(SELECT COUNT(PROFILE_NUM) PROFILE_COUNT " & _  
                                                                ", PROJECT_NUM " & _  
                                                                "FROM SIMBBA.PROFILES " & _  
                                                                "WHERE PROJECT_NUM = " & intProjectNumber & " GROUP BY PROJECT_NUM) C " & _  
                                                                "WHERE C.PROJECT_NUM=A.PROJECT_NUMBER(+) " & _  
                                                                "AND C.PROJECT_NUM=B.PROJECT_NUMBER(+)" 
 
            End If 
        Else 
          
End If 
 
          
End Sub 
 
 Public Function GetDataTable(ByVal query As StringAs DataTable  
        Dim objConn As New OracleConnection(txtConnectionString.Text)  
        Dim oDA As New OracleDataAdapter  
        oDA.SelectCommand = New OracleCommand(query, objConn)  
        Dim tbl As New DataTable  
        objConn.Open()  
        Try 
            oDA.Fill(tbl)  
        Finally 
            objConn.Close()  
        End Try 
        Return tbl  
    End Function 
 
 Protected Sub rgProjects_ItemCommand(ByVal source As ObjectByVal e As GridCommandEventArgs) Handles rgProjects.ItemCommand  
        Dim TaskNumber As String = Nothing 
        Dim selectedItems As ArrayList  
 
        If Session("selectedItems"Is Nothing Then 
            selectedItems = New ArrayList  
        Else 
            selectedItems = CType(Session("selectedItems"), ArrayList)  
        End If 
 
        If e.CommandName = "RowClick" And e.Item.OwnerTableView.Name = "Tasks" Then 
            selectedItems.Clear()  
            For Each selecteditem As GridDataItem In rgProjects.SelectedItems  
                TaskNumber = selecteditem.OwnerTableView.Items(selecteditem.ItemIndex)("Task_Number").Text  
                selectedItems.Add(TaskNumber)  
                Session("selectedItems") = selectedItems  
            Next 
        End If 
 
        rgProjects.Controls.Add(New LiteralControl(String.Format("<span style='color:green;font-weight:bolder;'>{0}</span>", e.CommandName.ToString)))  
    End Sub 
 
    Protected Sub rgProjects_PreRender(ByVal sender As ObjectByVal e As EventArgs) Handles rgProjects.PreRender  
 
        If Not (Session("selectedItems"Is NothingThen 
 
            Dim selectedItems As ArrayList = CType(Session("selectedItems"), ArrayList)  
            Dim stackIndex As Integer 
 
            For stackIndex = 0 To selectedItems.Count - 1  
                Dim curItem As String = selectedItems(stackIndex).ToString  
 
                For Each item As GridItem In rgProjects.Items  
                    If TypeOf item Is GridDataItem And item.OwnerTableView.Name = "Tasks" Then 
                        Dim dataItem As GridDataItem = CType(item, GridDataItem)  
                        If curItem.Equals(item.OwnerTableView.Items(item.ItemIndex)("Task_Number").Text) Then 
                            dataItem.Selected = True 
                        End If 
                    End If 
                Next 
 
            Next 
 
            lblSelDataKeys.Text = "Selected Item Count: " & selectedItems.Count & " Stack Index: " & stackIndex  
        End If 
    End Sub 
 
    Private Sub rgProjects_DetailTableDataBind(ByVal source As ObjectByVal e As GridDetailTableDataBindEventArgs) Handles rgProjects.DetailTableDataBind  
 
        Dim dataItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)  
        Dim nCurrentProfileNum As String = dataItem.GetDataKeyValue("Profile_Num").ToString()  
        e.DetailTableView.DataSource = GetDataTable("SELECT PROJECT_NUMBER, PROFILE_NUM, TASK_NUMBER, " & _  
                                                                        " TASK_DESCRIPTION, TASK_DESCRIPTION_B," & _  
                                                                        " TO_CHAR(DATE_CREATED, 'mm/dd/rr hh24:mi:ss') DATE_CREATED," & _  
                                                                        " GROUP_ASSIGNED, USER_ASSIGNED, COMPLETED_FLAG," & _  
                                                                        " TO_CHAR(DATE_ASSIGNED, 'mm/dd/rr hh24:mi:ss')" & _  
                                                                        " DATE_ASSIGNED, TO_CHAR(DATE_COMPLETED, 'mm/dd/rr hh24:mi:ss')  DATE_COMPLETED," & _  
                                                                        " USER_COMPLETED, ACTIVE_FLAG, USER_ASSIGNED_B," & _  
                                                                        " TO_CHAR(DATE_ACTIVATED, 'mm/dd/rr hh24:mi:ss') DATE_ACTIVATED," & _  
                                                                        " PROFILE_COORDINATOR, TASK_TYPE, PROFILE_CODE, " & _  
                                                                        " USER_INTERFACE_DATA, COM_IND " & _  
                                                                        " FROM SIMBBA.V_WEB_PROFILE_TASKS" & _  
                                                                        " WHERE PROFILE_NUM = " & nCurrentProfileNum & " order by task_number")  
 
    End Sub 
 
 Public Sub ExecuteOracleCommand(ByVal oExecuteQuery As String)  
 
        Dim oConnection As New OracleConnection(Session("ConnectionString"))  
        Dim oCommand As New OracleCommand(oExecuteQuery, oConnection)  
 
        oCommand.Connection.Open()  
 
        oCommand.ExecuteNonQuery()  
 
        oConnection.Close()  
 
        'Destroy the command object  
        oCommand.Dispose()  
 
        'Destroy the connection object  
        oConnection.Dispose()  
 
    End Sub 
 
 
End Class 
Tags
Grid
Asked by
codispdp
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
codispdp
Top achievements
Rank 1
Share this question
or