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

Prevent Details View From Being Edited

6 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tracy
Top achievements
Rank 1
Tracy asked on 13 Mar 2011, 03:25 AM
Hi,

I have 3 questions regarding a rad grid with a master/detail relationship.   All of my problems are the result of me not knowing how to reference the detail view items in code behind.


1.  In the master table view view I use the following to reference the items in command item template.

 

Dim cmdItem As GridCommandItem = DirectCast(rgvApplicationIdentifiers.MasterTableView.GetItems(GridItemType.CommandItem)(0), GridCommandItem)

 

How do I reference the command items in the details view?

And if the following code how do I distinguish between the master EditIndexes.Count and the details EditIndexes.Count?

 

 

 

 

Dim lnkAdd As LinkButton = TryCast(cmdItem.FindControl("lbtAdd"), LinkButton)

 

 

 

 

If

 

Me.rgvSecurityUsers.EditIndexes.Count = 0 And Not Me.rgvSecurityUsers.MasterTableView.IsItemInserted And Me.hdfAdd.Value = True Then

 

lnkAdd.Visible =

True

 

 

End If

 



2.  I have a rad grid that has a command item template for the master table view, that performs add/updates/inserts.  The details view has the command item display to none and the records in the details view should not be allowed to be edited, deleted or new records inserted.
My s that if I have a record selected in the details view and I click the edit button in the master table view it puts my details view in edit mode.  The details view records should not be able to be edited.  My master view grid is named  "Groups" and the details view is named "Users".  I thought I could could check for the e.Item.OwnerTableView.Name <> "Groups" and cancel the action if the tablename wasn't "Groups" but this did not work.  The tablename always returns "Groups".  I am guessing that I am not using the correct syntax to check if the details table has been selected.  So my question is what syntax should I use to check to see if the details view has been selected vs the master view?  The end result is that I am trying to prevent the Details view from going into edit mode when I click the Edit button on the master table view.

 

Case "EditSelected", "DeleteSelected"

 

 

If e.Item.OwnerTableView.Name <> "Groups" Or Me.rgvSecurityGroups.SelectedValue Is Nothing Then

 

 

Dim strMessage As String = "You must select a group before selecting this option."

 

 

Dim scriptstring As String = "radalert('" + strMessage + "', 330, 210, 'Missing Group');"

 

ScriptManager.RegisterStartupScript(

Me, Me.[GetType](), "radalert", scriptstring, True)

 

 

e.Canceled =

"true"

 

 

End If

 



3.  I have a grid that is a master/details view.  Both have a command item template that allows records to be added, edited or deleted.
If I select a record in the master grid and click the edit button, I get the following error message.
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.

If I remove the command item template from the details view, I do not get the error.

Below is my code.
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/IPSMaster.Master" CodeBehind="WBC SYS Application Identifiers.aspx.vb" Inherits="IPS_Gateway.WBC_SYS_Application_Identifiers" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="act" %>
    
<asp:Content ID="cntMain" ContentPlaceHolderID="cphMainContent" runat="server" >
<asp:SqlDataSource ID="SQLDS_Level1" runat="server"  ConnectionString="<%$ ConnectionStrings:IPSDataConnectionString %>"  
        SelectCommandType="StoredProcedure" SelectCommand="[Security].[DSP_SecurityIdentifiers-Sel-Ins-Upd-Del]" >
        <SelectParameters>
            <asp:Parameter Name="strCommandType" Type="String" DefaultValue="Select" />
        </SelectParameters>
        <SelectParameters>
            <asp:Parameter Name="intLevelNumber" Type="Int16"  DefaultValue="1" />
        </SelectParameters>
</asp:SqlDataSource>
  
<asp:SqlDataSource ID="SQLDS_Level2" runat="server"  ConnectionString="<%$ ConnectionStrings:IPSDataConnectionString %>"  
        SelectCommandType="StoredProcedure" SelectCommand="[Security].[DSP_SecurityIdentifiers-Sel-Ins-Upd-Del]" >
        <SelectParameters>
            <asp:Parameter Name="strCommandType" Type="String" DefaultValue="Select" />
        </SelectParameters>
        <SelectParameters>
            <asp:Parameter Name="intLevelNumber" Type="Int16"  DefaultValue="2" />
        </SelectParameters>
</asp:SqlDataSource>
  
<asp:SqlDataSource ID="SQLDS_Level3" runat="server"  ConnectionString="<%$ ConnectionStrings:IPSDataConnectionString %>"  
        SelectCommandType="StoredProcedure" SelectCommand="[Security].[DSP_SecurityIdentifiers-Sel-Ins-Upd-Del]" >
        <SelectParameters>
            <asp:Parameter Name="strCommandType" Type="String" DefaultValue="Select" />
        </SelectParameters>
        <SelectParameters>
            <asp:Parameter Name="intLevelNumber" Type="Int16"  DefaultValue="3" />
        </SelectParameters>
</asp:SqlDataSource>
  
  
<asp:panel ID="pnlPage"             runat="server"  SkinId="skn_GPC01_Panel_MainContent">
    <asp:panel ID="pnlStatus"       runat="server"  CssClass="css_GPC01_Panel_Status">
        <asp:Label ID="lblReadOnly" runat="server"  Text="Read Only" CssClass="css_GPC01_Label_Status"/>
        <asp:Label ID="lblAdd"      runat="server"  Text="Add"       CssClass="css_GPC01_Label_Status"/>
        <asp:Label ID="lblEdit"     runat="server"  Text="Edit"      CssClass="css_GPC01_Label_Status"/>        
        <asp:Label ID="lblDelete"   runat="server"  Text="Delete"    CssClass="css_GPC01_Label_Status"/>
        <asp:Label ID="lblObject"   runat="server"  Text="Object"    CssClass="css_GPC01_Label_Status"/>
        <asp:HiddenField ID="hdfReadOnly"   runat="server" />
        <asp:HiddenField ID="hdfAdd"        runat="server" />
        <asp:HiddenField ID="hdfEdit"       runat="server" />
        <asp:HiddenField ID="hdfDelete"     runat="server" />
    </asp:panel>
        
    <asp:panel ID="pnlPageHeader"                runat="server"  cssClass="css_GPC01_Panel_PageHeading" >       
        <asp:Label ID="lblPageTitle"             runat="server"  CssClass="css_GPC01_Label_PageTitle" Text="Security Identifiers" />   
        <asp:ImageButton ID="ibtPageInformation" runat="server"  SkinID="skn_GPC01_ImageButton_PageInformation"  />
    </asp:panel>    
  
  
    <asp:panel ID="pnlPageContent"               runat="server"  cssClass="css_GPC01_Panel_PageContent" >     
        <asp:UpdatePanel ID="uppGrid" runat="server" >
            <ContentTemplate>
                                            
                <telerik:RadGrid ID="rgvApplicationIdentifiers"   runat="server"  DataSourceID="SQLDS_Level1" 
                                 EnableEmbeddedSkins="true"     Skin="WebBlue"
                                 EnableViewState="true"                 
                                 AutoGenerateColumns="False"
                                 AllowMultiRowSelection="false" 
                                 AllowAutomaticDeletes="True" 
                                 AllowAutomaticInserts="True"  
                                 AllowAutomaticUpdates="True"                                   
                                 AllowFilteringByColumn="False"  
                                 EnableLinqExpressions="false"
                                 AllowPaging="True" PageSize="50"                              
                                 height="560px" Width="1038px">
                    <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" />
                    <ItemStyle Wrap="false" />
                      
                  <ClientSettings AllowColumnsReorder="false" EnablePostBackOnRowClick="true" AllowExpandCollapse="true"   >  
                        <Selecting AllowRowSelect="true" />
                        <Scrolling AllowScroll="true" UseStaticHeaders="true" />
                    </ClientSettings>
                    <MasterTableView DataSourceID="SQLDS_Level1" DataKeyNames="Level1Code, Level2Code, Level3Code, LevelNumber"    EnableViewState="true"  
                                       ExpandCollapseColumn-ButtonType ="ImageButton"
                                      ExpandCollapseColumn-CollapseImageUrl="../../App_Themes/Images/General/Expand Pale Blue 16.png"
                                      ExpandCollapseColumn-ExpandImageUrl= "../../App_Themes/Images/General/Expand Pale Blue 16.png"
  
                                     EditMode="InPlace"          CommandItemDisplay="Top"  Name="Level1" >
                        <CommandItemTemplate >
                            <div style="padding: 5px 5px;">
                                <asp:LinkButton ID="lbtAdd"           runat="server" CommandName="InitInsert"           ToolTip="Add New Group"               Visible='<%# rgvApplicationIdentifiers.EditIndexes.Count = 0 or Not rgvApplicationIdentifiers.MasterTableView.IsItemInserted %>'>     <asp:Image ID="imgAdd"           runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,AddRecord20%>" /> Add </asp:LinkButton>  
                                <asp:LinkButton ID="lbtEdit"          runat="server" CommandName="EditSelected"         ToolTip="Edit Group"                  Visible='<%# rgvApplicationIdentifiers.EditIndexes.Count=0 and Not rgvApplicationIdentifiers.MasterTableView.IsItemInserted %>'>     <asp:Image ID="imgEdit"          runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,EditRecord20%>"/> Edit </asp:LinkButton>  
                                <asp:LinkButton ID="lbtCancel"        runat="server" CommandName="CancelAll"            ToolTip="Cancel Edit/Add"             Visible='<%# rgvApplicationIdentifiers.EditIndexes.Count > 0 Or rgvApplicationIdentifiers.MasterTableView.IsItemInserted %>'>                              <asp:Image ID="imgCancel"        runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,CancelRecord20%>" /> Cancel </asp:LinkButton>  
                                <asp:LinkButton ID="lbtSaveNew"       runat="server" CommandName="PerformInsert"        ToolTip="Save New Group"              Visible='<%# rgvApplicationIdentifiers.MasterTableView.IsItemInserted%>'>                                                                         <asp:Image ID="imgSaveNew"       runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,SaveRecord20%>" /> Save New</asp:LinkButton>  
                                <asp:LinkButton ID="lbtDelete"        runat="server" CommandName="DeleteSelected"       ToolTip="Delete Group"                Visible='<%# rgvApplicationIdentifiers.EditIndexes.Count=0 and Not rgvApplicationIdentifiers.MasterTableView.IsItemInserted %>' OnClientClick="javascript:return confirm('You have selected to delete this user.<br>This process CANNOT BE UNDONE. <br> <br> Do you want to continue?')"> <asp:Image ID="imgDelete"        runat="server" CssClass="css_GFS01_Image_Align"  ImageURL="<%$ Resources:Images,DeleteRecord20%>" />Delete </asp:LinkButton>  
                                <asp:LinkButton ID="lbtSave"          runat="server" CommandName="UpdateEdited"         ToolTip="Save Changes"                Visible='<%# rgvApplicationIdentifiers.EditIndexes.Count > 0 AND Not rgvApplicationIdentifiers.MasterTableView.IsItemInserted%>'>                          <asp:Image ID="imgSave"          runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,SaveRecord20%>" />  Update </asp:LinkButton>  
                                <asp:LinkButton ID="lbtFilters"       runat="server" CommandName="ShowHideFilters"      style="position:absolute;left:800px;" ToolTip="Show/Hide Filters"           >                           <asp:Image ID="Image2" runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,Filter20%>" /> Show/Hide Filter</asp:LinkButton>  
                                <asp:LinkButton ID="lbtRefresh"       runat="server" CommandName="RebindGrid"           style="position:absolute;Left:930px;" >                                                                                                                                         <asp:Image id="imgRefresh"       runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$Resources:Images, ReloadBlue20 %>"  />Refresh Grid</asp:LinkButton>                     
                            </div>
                        </CommandItemTemplate>
                            <Columns>   
                                <telerik:GridBoundColumn     DataField="Level1Code"      UniqueName="Level1Code"             HeaderText="Id"            HeaderStyle-HorizontalAlign="Center"     HeaderStyle-Width="100px"   />
                                <telerik:GridTemplateColumn                                 HeaderText="Total Levels"  HeaderStyle-HorizontalAlign="Center"     HeaderStyle-Width="60px" ItemStyle-HorizontalAlign="Center">
                                     <ItemTemplate>
                                        <asp:Label ID="TotalLevels" runat="server" Text='<%# Bind("TotalLevels") %>' />
                                     </ItemTemplate>
                                     <EditItemTemplate>
                                        <telerik:RadComboBox runat="server" ID="rcbTotalLevels" 
                                                             AppendDataBoundItems="true"                    AutoPostBack="true"
                                                             EnableEmbeddedSkins="true"                     Skin="WebBlue"
                                                             Width="50px"                                  AllowCustomText="false" >                   
                                                               
                                            <Items>
                                                <telerik:RadComboBoxItem Text="2" />
                                                <telerik:RadComboBoxItem Text="3" />
                                            </Items>
                                        </telerik:RadComboBox>                                                                                                                                  
  
                                    </EditItemTemplate>
                                     <InsertItemTemplate>
                                        <telerik:RadComboBox runat="server" ID="rcbTotalLevelsInsert" 
                                                             AppendDataBoundItems="true"                    AutoPostBack="true"
                                                             EnableEmbeddedSkins="true"                     Skin="WebBlue"
                                                             Width="50px"                                  AllowCustomText="false" >                   
                                                               
                                            <Items>
                                                <telerik:RadComboBoxItem Text="2" />
                                                <telerik:RadComboBoxItem Text="3" />
                                            </Items>
                                        </telerik:RadComboBox>                                                                                                                                  
  
                                    </InsertItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderText="Use Identifier Code?" HeaderStyle-Width="100px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:CheckBox ID="chkUseIdentifierCode" runat="server"  Checked='<%# Bind("UseIdentifierCode") %>'   />
                                    </ItemTemplate>
                                    <InsertItemTemplate>
                                        <asp:CheckBox ID="chkUseIdentifierCodeInsert" runat="server"   />
                                    </InsertItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderText="Show In Sort?" HeaderStyle-Width="100px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:CheckBox ID="chkShowInSort" runat="server"  Checked='<%# Bind("ShowInSort") %>'  />
                                    </ItemTemplate>
                                    <InsertItemTemplate>
                                        <asp:CheckBox ID="chkShowInSortInsert" runat="server"   />
                                    </InsertItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderText="Active?" HeaderStyle-Width="100px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:CheckBox ID="chkActiveFlag" runat="server"  Checked='<%# Bind("ActiveFlag") %>' />
                                    </ItemTemplate>
                                    <InsertItemTemplate>
                                        <asp:CheckBox ID="chkActiveFlagInsert" runat="server"   />
                                    </InsertItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderStyle-Width="300px" ></telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn DataField="LevelNumber"     UniqueName="LevelNumber"    DefaultInsertValue="1"         Visible="false"  DataType="System.Int16" />
                            </Columns>
                            <DetailTables>
                                <telerik:GridTableView   DataKeyNames="Level1Code, Level2Code, Level3Code" HierarchyLoadMode="ServerOnDemand"  Name="Level2" EditMode="InPlace" CommandItemDisplay="Top" >
                                    <CommandItemTemplate >
                                        <div style="padding: 5px 5px;">
                                            <asp:LinkButton ID="lbtAdd"           runat="server" CommandName="InitInsert"           ToolTip="Add New Group"               Visible='<%# rgvApplicationIdentifiers.EditIndexes.Count = 0 or Not rgvApplicationIdentifiers.MasterTableView.IsItemInserted %>'>     <asp:Image ID="imgAdd"           runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,AddRecord20%>" /> Add </asp:LinkButton>  
                                            <asp:LinkButton ID="lbtEdit"          runat="server" CommandName="EditSelected"         ToolTip="Edit Group"                  Visible='<%# rgvApplicationIdentifiers.EditIndexes.Count=0 and Not rgvApplicationIdentifiers.MasterTableView.IsItemInserted %>'>     <asp:Image ID="imgEdit"          runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,EditRecord20%>"/> Edit </asp:LinkButton>  
                                            <asp:LinkButton ID="lbtCancel"        runat="server" CommandName="CancelAll"            ToolTip="Cancel Edit/Add"             Visible='<%# rgvApplicationIdentifiers.EditIndexes.Count > 0 Or rgvApplicationIdentifiers.MasterTableView.IsItemInserted %>'>                              <asp:Image ID="imgCancel"        runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,CancelRecord20%>" /> Cancel </asp:LinkButton>  
                                            <asp:LinkButton ID="lbtSaveNew"       runat="server" CommandName="PerformInsert"        ToolTip="Save New Group"              Visible='<%# rgvApplicationIdentifiers.MasterTableView.IsItemInserted%>'>                                                                         <asp:Image ID="imgSaveNew"       runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,SaveRecord20%>" /> Save New</asp:LinkButton>  
                                            <asp:LinkButton ID="lbtDelete"        runat="server" CommandName="DeleteSelected"       ToolTip="Delete Group"                Visible='<%# rgvApplicationIdentifiers.EditIndexes.Count=0 and Not rgvApplicationIdentifiers.MasterTableView.IsItemInserted %>' OnClientClick="javascript:return confirm('You have selected to delete this user.<br>This process CANNOT BE UNDONE. <br> <br> Do you want to continue?')"> <asp:Image ID="imgDelete"        runat="server" CssClass="css_GFS01_Image_Align"  ImageURL="<%$ Resources:Images,DeleteRecord20%>" />Delete </asp:LinkButton>  
                                            <asp:LinkButton ID="lbtSave"          runat="server" CommandName="UpdateEdited"         ToolTip="Save Changes"                Visible='<%# rgvApplicationIdentifiers.EditIndexes.Count > 0 AND Not rgvApplicationIdentifiers.MasterTableView.IsItemInserted%>'>                          <asp:Image ID="imgSave"          runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,SaveRecord20%>" />  Update </asp:LinkButton>  
                                            <asp:LinkButton ID="lbtFilters"       runat="server" CommandName="ShowHideFilters"      style="position:absolute;left:800px;" ToolTip="Show/Hide Filters"           >                           <asp:Image ID="Image2" runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,Filter20%>" /> Show/Hide Filter</asp:LinkButton>  
                                            <asp:LinkButton ID="lbtRefresh"       runat="server" CommandName="RebindGrid"           style="position:absolute;Left:930px;" >                                                                                                                                         <asp:Image id="imgRefresh"       runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$Resources:Images, ReloadBlue20 %>"  />Refresh Grid</asp:LinkButton>                     
                                        </div>
                                    </CommandItemTemplate>
                                                <Columns>
                                        <telerik:GridBoundColumn DataField="Level1Code"          UniqueName="Level1Code"         Visible="false" />
                                        <telerik:GridBoundColumn DataField="Level2Code"          UniqueName="Level2Code"         HeaderText="Level 2 Code"            HeaderStyle-HorizontalAlign="Left"     HeaderStyle-Width="150px"  ItemStyle-HorizontalAlign="Left"     />
                                        <telerik:GridBoundColumn DataField="Level3Code"          UniqueName="Level3Code"         Visible="false"   />
                                        <telerik:GridBoundColumn DataField="IdentifierCode"      UniqueName="IdentifierCode" HeaderText="Identifier Code"   HeaderStyle-HorizontalAlign="Left"     HeaderStyle-Width="150px"   />
                                        <telerik:GridTemplateColumn HeaderText="Use Identifier Code?" HeaderStyle-Width="100px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
                                            <ItemTemplate>
                                                 
                                                <asp:CheckBox ID="chkUseIdentifierCode" runat="server"  Checked='<%# Bind("UseIdentifierCode") %>'   />
                                            </ItemTemplate>
                                            <InsertItemTemplate>
                                                <asp:CheckBox ID="chkUseIdentifierCodeInsert" runat="server"    />
                                            </InsertItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn                                                      HeaderText="Show In Sort?"     HeaderStyle-HorizontalAlign="Center"   HeaderStyle-Width="100px"   ItemStyle-HorizontalAlign="Center">
                                            <ItemTemplate>
                                                <asp:CheckBox ID="chkShowInSort" runat="server"  Checked='<%# Bind("ShowInSort") %>'   />
                                            </ItemTemplate>
                                            <InsertItemTemplate>
                                                <asp:CheckBox ID="chkShowInSortInsert" runat="server"   />
                                            </InsertItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn                                                      HeaderText="Active?"           HeaderStyle-HorizontalAlign="Center"   HeaderStyle-Width="100px"   ItemStyle-HorizontalAlign="Center">
                                            <ItemTemplate>
                                                <asp:CheckBox ID="chkActiveFlag" runat="server"  Checked='<%# Bind("ActiveFlag") %>' />
                                            </ItemTemplate>
                                            <InsertItemTemplate>
                                                <asp:CheckBox ID="chkActiveFlagInsert" runat="server"   />
                                            </InsertItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridBoundColumn DataField="LevelNumber"     UniqueName="LevelNumber"    DefaultInsertValue="2"         Visible="false"  DataType="System.Int16" />
                                        <telerik:GridBoundColumn DataField="TotalLevels"     UniqueName="TotalLevels"    DefaultInsertValue="0"         Visible="false"  DataType="System.Int16" />
                                    </Columns>
                                </telerik:GridTableView>
                              
                            </DetailTables>
                    </MasterTableView>
                </telerik:RadGrid>
                <telerik:GridTextBoxColumnEditor ID="gtcEditor1" runat="server" TextBoxStyle-Width="150px" />         <telerik:RadWindowManager ID="rwmMessageBox" runat="server" Behaviors="Close, Move"  EnableViewState="false" Animation="Slide" AnimationDuration="5"  Height="400" Width="400" VisibleOnPageLoad="true" DestroyOnClose="true"  Modal="true"   EnableEmbeddedSkins="true" Skin="Black" />
            </ContentTemplate>
        </asp:UpdatePanel>
  
    </asp:panel>
</asp:panel
</asp:Content>
Imports IPS_Gateway.CLS_Data_Retrieval
Imports IPS_Gateway.CLS_String_Functions
Imports Telerik.Web.UI
Imports System.Data.SqlClient
Imports System.Drawing
Partial Public Class WBC_SYS_Application_Identifiers
    Inherits System.Web.UI.Page
   
    Private Sub rgvApplicationIdentifiers_DeleteCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgvApplicationIdentifiers.DeleteCommand
  
        Dim GridItem As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim strLevel1 As String = GridItem.GetDataKeyValue("Level1Code")
        Dim strLevel2 As String = GridItem.GetDataKeyValue("Level2Code")
        Dim strLevel3 As String = GridItem.GetDataKeyValue("Level3Code")
        Dim intLevelNumber As Integer = 0
        Dim strLogonUser As String = Request.ServerVariables("AUTH_USER")
        Select Case e.Item.OwnerTableView.Name
            Case "Level1"
                intLevelNumber = 1
                Me.SQLDS_Level1.DeleteCommandType = SqlDataSourceCommandType.Text
                Me.SQLDS_Level1.DeleteCommand = "[Security].[DSP_SecurityIdentifiers-Sel-Ins-Upd-Del] 'Delete', '" + strLevel1 + "', '" + strLevel2 + "', '" + strLevel3 + "', " + intLevelNumber.ToString + ", NULL,  NULL, NULL, NULL, NULL, '" + strLogonUser + "'"
            Case "Level2"
                intLevelNumber = 2
                Me.SQLDS_Level2.DeleteCommandType = SqlDataSourceCommandType.Text
                Me.SQLDS_Level2.DeleteCommand = "[Security].[DSP_SecurityIdentifiers-Sel-Ins-Upd-Del] 'Delete', '" + strLevel1 + "', '" + strLevel2 + "', '" + strLevel3 + "', " + intLevelNumber.ToString + ", NULL,  NULL, NULL, NULL, NULL, '" + strLogonUser + "'"
            Case "Level3"
                intLevelNumber = 3
                Me.SQLDS_Level3.DeleteCommandType = SqlDataSourceCommandType.Text
                Me.SQLDS_Level3.DeleteCommand = "[Security].[DSP_SecurityIdentifiers-Sel-Ins-Upd-Del] 'Delete', '" + strLevel1 + "', '" + strLevel2 + "', '" + strLevel3 + "', " + intLevelNumber.ToString + ", NULL,  NULL, NULL, NULL, NULL, '" + strLogonUser + "'"
        End Select
    End Sub
  
    Protected Sub rgvApplicationIdentifiers_ItemDeleted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDeletedEventArgs) Handles rgvApplicationIdentifiers.ItemDeleted
   
        If Not e.Exception Is Nothing Then
            Dim GridItem As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim strMessage As String = "Identifier cannot be deleted. <br> Reason: " + e.Exception.Message
            Dim scriptstring As String = "radalert('" + strMessage + "', 330, 210, 'Error Deleting Identifier');"
            e.ExceptionHandled = True
            ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "radalert", scriptstring, True)
        End If
  
    End Sub
  
    Private Sub rgvApplicationIdentifiers_UpdateCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgvApplicationIdentifiers.UpdateCommand
        Dim ParentItem As GridDataItem
        Dim EditedItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
        Dim strLevel1 As String = Nothing
        Dim strLevel2 As String = "Unassigned"
        Dim strLevel3 As String = "Unassigned"
        Dim strIdentifierCode As String = Nothing
        Dim intLevelNumber As Integer = 0
        Dim intTotalLevels As Integer = 0
        Dim bitShowInSort As Boolean = Nothing
        Dim bitActiveFlag As Boolean = Nothing
        Dim strLogonUser As String = Request.ServerVariables("AUTH_USER")
        Dim strMessage As String = Nothing
        Dim scriptstring As String = "radalert('" + strMessage + "', 330, 210,'Invalid Field Value');"
        Select e.Item.OwnerTableView.Name
            Case "Level1"
                strLevel1 = DirectCast(EditedItem("Level1").Controls(0), TextBox).Text
                intLevelNumber = "1"
                intTotalLevels = DirectCast(EditedItem.FindControl("rcbTotalLevels"), RadComboBox).Text
                bitShowInSort = DirectCast(EditedItem.FindControl("chkShowInSort"), CheckBox).Checked
                bitActiveFlag = DirectCast(EditedItem.FindControl("chkActiveFlag"), CheckBox).Checked
                Me.SQLDS_Level1.UpdateCommandType = SqlDataSourceCommandType.Text
                Me.SQLDS_Level1.UpdateCommand = "[Security].[DSP_SecurityIdentifiers-Sel-Ins-Upd-Del] 'Update', '" + strLevel1 + "', '" + strLevel2 + "', '" + strLevel3 + "', '" + intLevelNumber.ToString + "', '" + intTotalLevels.ToString + "', '" + strIdentifierCode + "', '" + bitShowInSort.ToString + "', '" + bitActiveFlag.ToString + "', '" + strLogonUser + "'"
            Case "Level2"
                ParentItem = DirectCast(e.Item.OwnerTableView.ParentItem, GridDataItem)
                strLevel1 = DirectCast(ParentItem("Level1Code").Controls(0), TextBox).Text
                strLevel2 = DirectCast(EditedItem("Level2Code").Controls(0), TextBox).Text
                strIdentifierCode = DirectCast(EditedItem("IdentifierCode").Controls(0), TextBox).Text
                intLevelNumber = "2"
                bitShowInSort = DirectCast(EditedItem.FindControl("chkShowInSort"), CheckBox).Checked
                bitActiveFlag = DirectCast(EditedItem.FindControl("chkActiveFlag"), CheckBox).Checked
                Me.SQLDS_Level2.UpdateCommandType = SqlDataSourceCommandType.Text
                Me.SQLDS_Level2.UpdateCommand = "[Security].[DSP_SecurityIdentifiers-Sel-Ins-Upd-Del] 'Update', '" + strLevel1 + "', '" + strLevel2 + "', '" + strLevel3 + "', '" + intLevelNumber.ToString + "', '" + intTotalLevels.ToString + "', '" + strIdentifierCode + "', '" + bitShowInSort.ToString + "', '" + bitActiveFlag.ToString + "', '" + strLogonUser + "'"
            Case "Level3"
                ParentItem = DirectCast(e.Item.OwnerTableView.ParentItem, GridDataItem)
                strLevel1 = DirectCast(ParentItem("Level1Code").Controls(0), TextBox).Text
                strLevel2 = DirectCast(ParentItem("Level2Code").Controls(0), TextBox).Text
                strLevel3 = DirectCast(EditedItem("Level3Code").Controls(0), TextBox).Text
                strIdentifierCode = DirectCast(EditedItem("IdentifierCode").Controls(0), TextBox).Text
                intLevelNumber = "3"
                bitShowInSort = DirectCast(EditedItem.FindControl("chkShowInSort"), CheckBox).Checked
                bitActiveFlag = DirectCast(EditedItem.FindControl("chkActiveFlag"), CheckBox).Checked
                Me.SQLDS_Level3.UpdateCommandType = SqlDataSourceCommandType.Text
                Me.SQLDS_Level3.UpdateCommand = "[Security].[DSP_SecurityIdentifiers-Sel-Ins-Upd-Del] 'Update', '" + strLevel1 + "', '" + strLevel2 + "', '" + strLevel3 + "', '" + intLevelNumber.ToString + "', '" + intTotalLevels.ToString + "', '" + strIdentifierCode + "', '" + bitShowInSort.ToString + "', '" + bitActiveFlag.ToString + "', '" + strLogonUser + "'"
        End Select
  
    End Sub
  
    Protected Sub rgvApplicationIdentifiers_ItemUpdated(ByVal source As Object, ByVal e As Telerik.Web.UI.GridUpdatedEventArgs) Handles rgvApplicationIdentifiers.ItemUpdated
        If Not e.Exception Is Nothing Then
            Dim EditItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
            Dim strMessage As String = "Identifier cannot be updated. <br> Reason: " + e.Exception.Message
            Dim scriptstring As String = "radalert('" + strMessage + "', 250, 300, 'Error Updating Indentifier');"
            e.KeepInEditMode = True
            e.ExceptionHandled = True
            ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "radalert", scriptstring, True)
        End If
    End Sub
  
    Private Sub rgvApplicationIdentifiers_InsertCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgvApplicationIdentifiers.InsertCommand
        Dim ParentItem As GridDataItem
        Dim InsertItem As GridDataInsertItem = DirectCast(e.Item.OwnerTableView.GetInsertItem(), GridDataInsertItem)
        Dim strLevel1Code As String = Nothing
        Dim strLevel2 As String = "Unassigned"
        Dim strLevel3 As String = "Unassigned"
        Dim strIdentifierCode As String = "DEFAULT"
        Dim intLevelNumber As Integer = 0
        Dim intTotalLevels As Integer = 0
        Dim bitUseIdentifier As Boolean = Nothing
        Dim bitShowInSort As Boolean = Nothing
        Dim bitActiveFlag As Boolean = Nothing
        Dim strLogonUser As String = Request.ServerVariables("AUTH_USER")
        Dim strMessage As String = Nothing
        Dim scriptstring As String = "radalert('" + strMessage + "', 330, 210,'Invalid Field Value');"
        Select Case e.Item.OwnerTableView.Name
            Case "Level1"
                strLevel1Code = DirectCast(InsertItem("Level1Code").Controls(0), TextBox).Text
                intLevelNumber = 1
                intTotalLevels = DirectCast(InsertItem.FindControl("rcbTotalLevelsInsert"), RadComboBox).Text
                bitUseIdentifier = DirectCast(InsertItem.FindControl("chkUseIdentifierCodeInsert"), CheckBox).Checked
                bitShowInSort = DirectCast(InsertItem.FindControl("chkShowInSortInsert"), CheckBox).Checked
                bitActiveFlag = DirectCast(InsertItem.FindControl("chkActiveFlagInsert"), CheckBox).Checked
                Me.SQLDS_Level1.InsertCommandType = SqlDataSourceCommandType.Text
                Me.SQLDS_Level1.InsertCommand = "[Security].[DSP_SecurityIdentifiers-Sel-Ins-Upd-Del] 'Insert', '" + strLevel1Code + "', '" + strLevel2 + "', '" + strLevel3 + "', " + intLevelNumber.ToString + ", " + intTotalLevels.ToString + ", " + bitUseIdentifier.ToString + ", NULL, " + bitShowInSort.ToString + ", " + bitActiveFlag.ToString + ", '" + strLogonUser + "'"
            Case "Level2"
                ParentItem = DirectCast(e.Item.OwnerTableView.ParentItem, GridDataItem)
                strLevel1Code = DirectCast(ParentItem("Level1Code").Controls(0), TextBox).Text
                strLevel2 = DirectCast(InsertItem("Level2Code").Controls(0), TextBox).Text
                strIdentifierCode = DirectCast(InsertItem("IdentifierCode").Controls(0), TextBox).Text
                intLevelNumber = 2
                intTotalLevels = 0
                bitUseIdentifier = DirectCast(InsertItem.FindControl("chkUseIdentifierCodeInsert"), CheckBox).Checked
                bitShowInSort = DirectCast(InsertItem.FindControl("chkShowInSortInsert"), CheckBox).Checked
                bitActiveFlag = DirectCast(InsertItem.FindControl("chkActiveFlagInsert"), CheckBox).Checked
                Me.SQLDS_Level2.InsertCommandType = SqlDataSourceCommandType.Text
                Me.SQLDS_Level2.InsertCommand = "[Security].[DSP_SecurityIdentifiers-Sel-Ins-Upd-Del] 'Insert', '" + strLevel1Code + "', '" + strLevel2 + "', '" + strLevel3 + "', " + intLevelNumber.ToString + ", " + intTotalLevels.ToString + ", " + bitUseIdentifier.ToString + ", '" + strIdentifierCode + "', " + bitShowInSort.ToString + ", " + bitActiveFlag.ToString + ", '" + strLogonUser + "'"
            Case "Level3"
                ParentItem = DirectCast(e.Item.OwnerTableView.ParentItem, GridDataItem)
                strLevel1Code = DirectCast(ParentItem("Level1Code").Controls(0), TextBox).Text
                strLevel2 = DirectCast(ParentItem("Level2Code").Controls(0), TextBox).Text
                strLevel3 = DirectCast(InsertItem("Level3Code").Controls(0), TextBox).Text
                strIdentifierCode = DirectCast(InsertItem("IdentifierCode").Controls(0), TextBox).Text
                intLevelNumber = 3
                intTotalLevels = 0
                bitUseIdentifier = DirectCast(InsertItem.FindControl("chkUseIdentifierCodeInsert"), CheckBox).Checked
                bitShowInSort = DirectCast(InsertItem.FindControl("chkShowInSortInsert"), CheckBox).Checked
                bitActiveFlag = DirectCast(InsertItem.FindControl("chkActiveFlagInsert"), CheckBox).Checked
                Me.SQLDS_Level3.InsertCommandType = SqlDataSourceCommandType.Text
                Me.SQLDS_Level3.InsertCommand = "[Security].[DSP_SecurityIdentifiers-Sel-Ins-Upd-Del] 'Insert', '" + strLevel1Code + "', '" + strLevel2 + "', '" + strLevel3 + "', " + intLevelNumber.ToString + ", " + intTotalLevels.ToString + ", " + bitUseIdentifier.ToString + ", '" + strIdentifierCode + "', " + bitShowInSort.ToString + ", " + bitActiveFlag.ToString + ", '" + strLogonUser + "'"
        End Select
  
  
    End Sub
  
    Protected Sub rgvApplicationIdentifiers_ItemInserted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridInsertedEventArgs) Handles rgvApplicationIdentifiers.ItemInserted
     
        If Not e.Exception Is Nothing Then
            Dim strMessage As String = "Identifier cannot be added. <br> Reason: " + e.Exception.Message
            Dim scriptstring As String = "radalert('" + strMessage + "', 330, 210, 'Error On Item Insert');"
            e.ExceptionHandled = True
            e.KeepInInsertMode = True
            ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "radalert", scriptstring, True)
        End If
    End Sub
  
    Private Sub WBC_SEC_Security_Groups_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If Request("Source") IsNot Nothing Then
                If Request("Level1") <> "All" Then
                    SQLDS_Level1.SelectParameters.Add("strLevel1", Request("Level1"))
                    SQLDS_Level1.SelectParameters.Add("intLevelNumber", "2")
                    Me.lblPageTitle.Text = Request("Source") + " " + Request("Level1")
                Else
                    Me.lblPageTitle.Text = Request("Source") + " Identifiers"
                End If
                Dim strSelectCommand As String = "[" + Request("Source") + "].[DSP_" + Request("Source") + "Identifiers-Sel-Ins-Upd-Del]"
                Dim strSecurityString As String = If(Request("SecurityString") = Nothing, "1,0,0,0", Request("SecurityString"))
                Me.lblObject.Text = If(Request("ObjectId") = Nothing, "Unknown", Request("ObjectId"))
                Dim aryString As String() = strSecurityString.Split(",")
                hdfReadOnly.Value = aryString(0)
                Me.lblReadOnly.ForeColor = If(Me.hdfReadOnly.Value = False, Color.Gray, Color.Red)
                hdfAdd.Value = aryString(1)
                Me.lblAdd.ForeColor = If(Me.hdfAdd.Value = False, Color.Gray, Color.Red)
                hdfEdit.Value = aryString(2)
                Me.lblEdit.ForeColor = If(Me.hdfEdit.Value = False, Color.Gray, Color.Red)
                hdfDelete.Value = aryString(3)
                Me.lblDelete.ForeColor = If(Me.hdfDelete.Value = False, Color.Gray, Color.Red)
            End If
        End If
    End Sub
  
    Private Sub rgvApplicationIdentifiers_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgvApplicationIdentifiers.ItemCommand
  
        Select Case e.CommandName
            Case "ShowHideFilters"
                If rgvApplicationIdentifiers.AllowFilteringByColumn = True Then
                    rgvApplicationIdentifiers.AllowFilteringByColumn = False
                Else
                    rgvApplicationIdentifiers.AllowFilteringByColumn = True
                End If
                rgvApplicationIdentifiers.Rebind()
            Case "DeleteSelected"
                If rgvApplicationIdentifiers.SelectedValue Is Nothing Then
                    Dim strMessage As String = "You must select a row before selecting this option."
                    Dim scriptstring As String = "radalert('" + strMessage + "', 330, 210, 'Selected Row Is Null');"
                    ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "radalert", scriptstring, True)
                    e.Canceled = "true"
                End If
            Case "EditSelected"
  
                If rgvApplicationIdentifiers.SelectedValue Is Nothing Then
                    Dim strMessage As String = "You must select a row before selecting this option."
                    Dim scriptstring As String = "radalert('" + strMessage + "', 330, 210, 'Select Row Is Null');"
                    ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "radalert", scriptstring, True)
                    e.Canceled = "true"
                Else
  
                End If
            Case "RebindGrid"
                ViewState("FilterSecurityGroup") = "All"
                rgvApplicationIdentifiers.MasterTableView.FilterExpression = ""
                rgvApplicationIdentifiers.MasterTableView.Rebind()
        End Select
  
    End Sub
  
    Private Sub rgvApplicationIdentifiers_DetailTableDataBind(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles rgvApplicationIdentifiers.DetailTableDataBind
        Dim ParentRow As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)
        Dim strLevel1 As String = ParentRow.GetDataKeyValue("Level1Code")
        Dim strLevel2 As String = ParentRow.GetDataKeyValue("Level2Code")
        If e.DetailTableView.Name = "Level2" Then
            SQLDS_Level2.SelectParameters.Clear()
            SQLDS_Level2.SelectParameters.Add("strLevel1", strLevel1)
            SQLDS_Level2.SelectParameters.Add("intLevelNumber", "2")
            e.DetailTableView.DataSource = SQLDS_Level2
        ElseIf e.DetailTableView.Name = "Level3" Then
            SQLDS_Level3.SelectParameters.Clear()
            SQLDS_Level3.SelectParameters.Add("strLevel1", strLevel1)
            SQLDS_Level3.SelectParameters.Add("strLevel2", strLevel2)
            SQLDS_Level3.SelectParameters.Add("intLevelNumber", "3")
            e.DetailTableView.DataSource = SQLDS_Level3
        End If
    End Sub
  
   
  
    Private Sub rgvApplicationIdentifiers_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgvApplicationIdentifiers.ItemDataBound
        If (TypeOf e.Item Is GridEditableItem) AndAlso (e.Item.IsInEditMode) AndAlso (Not e.Item.OwnerTableView.IsItemInserted) Then
            Dim edititem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
            edititem("Level1Code").Enabled = False
        End If
  
    End Sub
End Class


Thank you for your assistance.

Tracy

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Mar 2011, 10:12 AM
Hello Tracy,

Try the following approach to access the CommandItem of detail table.

VB.NET:
Dim item As GridDataItem = DirectCast(rgvApplicationIdentifiers.Items(0), GridDataItem)
'access parent item of corresponding detailtable
Dim tableview As GridTableView = DirectCast(item.ChildItem.NestedTableViews(0), GridTableView)
'get corresponding child TableView
Dim detail_cmdItem As GridCommandItem = DirectCast(tableview.GetItems(GridItemType.CommandItem)(0), GridCommandItem)
'accessing GridCommandItem of Detailtable

And to achieve your second requirement give separate CommndName for Edit button in master and detal table and try the following code snippet.

ASPX:
<MasterTableView  Name="Level1">
    <CommandItemTemplate>
            <asp:LinkButton ID="lbtEdit" runat="server" CommandName="EditSelectedMasterTable" ToolTip="Edit Group">
                   Edit
            </asp:LinkButton>
            .    .    .    .     .    .
    </CommandItemTemplate>
    <Columns>
         .    .    .    .     .    .
    </Columns>
    <DetailTables>
        <telerik:GridTableView Name="Level2" >
            <CommandItemTemplate>
                   <asp:LinkButton ID="LinkButton2" runat="server" CommandName="EditDetailSelected" ToolTip="Edit Group">
                             Edit
                    </asp:LinkButton>
                       .    .    .    .     .    .
            </CommandItemTemplate>
    </DetailTables>
</MasterTableView>

VB.NET:
Protected Sub rgvApplicationIdentifiers_ItemCommand(sender As Object, e As GridCommandEventArgs)
    If e.CommandName = "EditDetailSelected" Then
 
        Dim tableview As GridTableView = DirectCast(e.Item.OwnerTableView, GridTableView)
        For Each item As GridDataItem In tableview.Items
            item.Edit = item.Selected
        Next
        tableview.Rebind()
    End If
    If e.CommandName = "EditSelectedMasterTable" Then
        For Each item As GridDataItem In rgvApplicationIdentifiers.SelectedItems
 
            item.Edit = True
        Next
        If rgvApplicationIdentifiers.SelectedItems.Count > 0 Then
 
            rgvApplicationIdentifiers.MasterTableView.Rebind()
        End If
    End If
End Sub

And I guess this will also eliminate the third issue .

Hope this helps,
Princy.
0
Tracy
Top achievements
Rank 1
answered on 14 Mar 2011, 07:11 PM
Hi Princy,

For item number 2, you suggested I change the name of the command items in both the master and the table view.  The problem is that the table view does not have a command item template.  I do not want the records in the table view to add/edited or inserted.

2.  I have a rad grid that has a command item template for the master table view, that performs add/updates/inserts.  The details view has the command item display to none and the records in the details view should not be allowed to be edited, deleted or new records inserted.
My problem is that if I have a record selected in the details view and I click the edit button in the master table view it puts my details view in edit mode.  The details view records should not be able to be edited. 
My master view grid is named  "Groups" and the details view is named "Users".  I thought I could could check for the e.Item.OwnerTableView.Name <> "Groups" and cancel the action if the tablename wasn't "Groups" but this did not work.  The tablename always returns "Groups".  I am guessing that I am not using the correct syntax to check if the details table has been selected.  So my question is what syntax should I use to check to see if the details view has been selected vs the master view?  The end result is that I am trying to prevent the Details view from going into edit mode when I click the Edit button on the master table view.

If e.Item.OwnerTableView.Name <> "Groups" Or Me.rgvSecurityGroups.SelectedValue Is Nothing Then
    Dim strMessage As String = "You must select a group before selecting this option."
    Dim scriptstring As String = "radalert('" + strMessage + "', 330, 210, 'Missing User');"
    ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "radalert", scriptstring, True)
    e.Canceled = "true"
Else
End If

For the 3rd Item I used the code you suggested but I get the error message Object reference not set to an instance of an object and the following line is highlighted.
rgvApplicationIdentifiers.MasterTableView.Rebind()

Case "EditSelected"
               For Each item As GridDataItem In rgvApplicationIdentifiers.SelectedItems
                   item.Edit = True
               Next
               If rgvApplicationIdentifiers.SelectedItems.Count > 0 Then
                   rgvApplicationIdentifiers.MasterTableView.Rebind()
               End If
           Case "EditSelectedDetail"
               Dim tableview As GridTableView = DirectCast(e.Item.OwnerTableView, GridTableView)
               For Each item As GridDataItem In tableview.Items
                   item.Edit = item.Selected
               Next
               tableview.Rebind()

The goods news is that it does let me edit the detail table, but the update command never fires.  I am guessing since I changed the name of the edit item in the command item template to EditSelectedDetail the built in update command doesn't work.  So the next question is how do I get the UpdateCommand to fire.

Private Sub rgvApplicationIdentifiers_UpdateCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgvApplicationIdentifiers.UpdateCommand
    Dim ParentItem As GridDataItem
    Dim EditedItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
    Dim strLevel1 As String = Nothing
    Dim strLevel2 As String = "Unassigned"
    Dim strLevel3 As String = "Unassigned"
    Dim strIdentifierCode As String = Nothing
    Dim intLevelNumber As Integer = 0
    Dim intTotalLevels As Integer = 0
    Dim bitShowInSort As Boolean = Nothing
    Dim bitActiveFlag As Boolean = Nothing
    Dim strLogonUser As String = Request.ServerVariables("AUTH_USER")
    Dim strMessage As String = Nothing
    Dim scriptstring As String = "radalert('" + strMessage + "', 330, 210,'Invalid Field Value');"
    Select e.Item.OwnerTableView.Name
        Case "Level1"
            strLevel1 = DirectCast(EditedItem("Level1").Controls(0), TextBox).Text
            intLevelNumber = "1"
            intTotalLevels = DirectCast(EditedItem.FindControl("rcbTotalLevels"), RadComboBox).Text
            bitShowInSort = DirectCast(EditedItem.FindControl("chkShowInSort"), CheckBox).Checked
            bitActiveFlag = DirectCast(EditedItem.FindControl("chkActiveFlag"), CheckBox).Checked
            Me.SQLDS_Level1.UpdateCommandType = SqlDataSourceCommandType.Text
            Me.SQLDS_Level1.UpdateCommand = "[Security].[DSP_SecurityIdentifiers-Sel-Ins-Upd-Del] 'Update', '" + strLevel1 + "', '" + strLevel2 + "', '" + strLevel3 + "', " + intLevelNumber.ToString + ", " + intTotalLevels.ToString + ", '" + strIdentifierCode + "', " + bitShowInSort.ToString + ", " + bitActiveFlag.ToString + ", '" + strLogonUser + "'"
        Case "Level2"
            strLevel1 = DirectCast(EditedItem("Level1CodeDetail").Controls(0), TextBox).Text
            strLevel2 = DirectCast(EditedItem("Level2CodeDetail").Controls(0), TextBox).Text
            strIdentifierCode = DirectCast(EditedItem("IdentifierCodeDetail").Controls(0), TextBox).Text
            intLevelNumber = "2"
            bitShowInSort = DirectCast(EditedItem.FindControl("chkShowInSortDetail"), CheckBox).Checked
            bitActiveFlag = DirectCast(EditedItem.FindControl("chkActiveFlagDetail"), CheckBox).Checked
            Me.SQLDS_Level2.UpdateCommandType = SqlDataSourceCommandType.Text
            Me.SQLDS_Level2.UpdateCommand = "[Security].[DSP_SecurityIdentifiers-Sel-Ins-Upd-Del] 'Update', '" + strLevel1 + "', '" + strLevel2 + "', '" + strLevel3 + "', " + intLevelNumber.ToString + ", " + intTotalLevels.ToString + ", '" + strIdentifierCode + "', " + bitShowInSort.ToString + ", " + bitActiveFlag.ToString + ", '" + strLogonUser + "'"
        Case "Level3"
            ParentItem = DirectCast(e.Item.OwnerTableView.ParentItem, GridDataItem)
            strLevel1 = DirectCast(ParentItem("Level1Code").Controls(0), TextBox).Text
            strLevel2 = DirectCast(ParentItem("Level2Code").Controls(0), TextBox).Text
            strLevel3 = DirectCast(EditedItem("Level3Code").Controls(0), TextBox).Text
            strIdentifierCode = DirectCast(EditedItem("IdentifierCode").Controls(0), TextBox).Text
            intLevelNumber = "3"
            bitShowInSort = DirectCast(EditedItem.FindControl("chkShowInSort"), CheckBox).Checked
            bitActiveFlag = DirectCast(EditedItem.FindControl("chkActiveFlag"), CheckBox).Checked
            Me.SQLDS_Level3.UpdateCommandType = SqlDataSourceCommandType.Text
            Me.SQLDS_Level3.UpdateCommand = "[Security].[DSP_SecurityIdentifiers-Sel-Ins-Upd-Del] 'Update', '" + strLevel1 + "', '" + strLevel2 + "', '" + strLevel3 + "', '" + intLevelNumber.ToString + "', '" + intTotalLevels.ToString + "', '" + strIdentifierCode + "', '" + bitShowInSort.ToString + "', '" + bitActiveFlag.ToString + "', '" + strLogonUser + "'"
    End Select
End Sub

Thank you for your assistance.
0
Princy
Top achievements
Rank 2
answered on 15 Mar 2011, 09:58 AM
Hello Tracy,

Can you please the make the following modification in your code and see if it works now. And also I haven't found any issue in firing UpdateCommand.

VB.NET:
Private flag1 As Boolean = False
Protected Sub rgvApplicationIdentifiers_ItemCommand(sender As Object, e As GridCommandEventArgs)
    If e.CommandName = "EditSelectedMasterTable" Then
        Dim tableview As GridTableView = DirectCast(e.Item.OwnerTableView, GridTableView)
        For Each item As GridDataItem In tableview.Items
            If item.Selected Then
                item.Edit = True
                flag1 = True
            End If
        Next
        If flag1 Then
            tableview.Rebind()
            flag1 = False
        End If
    End If
End Sub

Thanks,
Princy.
0
Tracy
Top achievements
Rank 1
answered on 16 Mar 2011, 03:58 AM
Hi Princy,

I am slowly getting this.  Thank you for your patience.

By changing the names on the detail command item template and adding the code you suggested to the command item event I have gotten the detail table to go into insert and edit mode.
How do I get the Delete functionality to work for the details table. Do I need to change its name and add code to the Item Command event also?
For the edit I put the row in edit mode by setting edit = True and for insert I set IsItemInserted = True.  Is there a delete mode? 

I am still having a problem with the Update command not firing when I click the Save button in the details view.  I put a message box in the Update Command event and it displays when I click the save button in the master table but not the details table so this tells me that it isn't firing when I click the save button.  The Insert command also does not fire from clicking the save button in the details view.

Details Table Command Item Template
<DetailTables >                            
    <telerik:GridTableView   DataKeyNames="Level1Code, Level2Code, Level3Code" HierarchyLoadMode="ServerOnDemand"  Name="Level2" EditMode="InPlace" CommandItemDisplay="Top" >
        <CommandItemTemplate >
            <div style="padding: 5px 5px;">
                <asp:LinkButton ID="lbtAddDetail"     runat="server" CommandName="InitInsertDetail"           ToolTip="Add New Group"               Visible='<%# Not CType(Container, GridCommandItem).OwnerTableView.IsItemInserted %>'>        <asp:Image ID="imgAdd"           runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,AddRecord20%>" /> Add </asp:LinkButton>  
                <asp:LinkButton ID="lbtEditDetail"    runat="server" CommandName="EditSelectedDetail"         ToolTip="Edit Group"                  Visible='<%# rgvApplicationIdentifiers.EditIndexes.Count=0 and Not CType(Container, GridCommandItem).OwnerTableView.IsItemInserted %>'>      <asp:Image ID="imgEdit"          runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,EditRecord20%>"/> Edit </asp:LinkButton>  
                <asp:LinkButton ID="lbtCancelDetail"  runat="server" CommandName="CancelAll"            ToolTip="Cancel Edit/Add"             Visible='<%# rgvApplicationIdentifiers.EditIndexes.Count > 0 Or CType(Container, GridCommandItem).OwnerTableView.IsItemInserted %>'>                                 <asp:Image ID="imgCancel"        runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,CancelRecord20%>" /> Cancel </asp:LinkButton>  
                <asp:LinkButton ID="lbtSaveNewDetail" runat="server" CommandName="PerformInsert"        ToolTip="Save New Group"              Visible='<%# CType(Container, GridCommandItem).OwnerTableView.IsItemInserted %>'>                                                                         <asp:Image ID="imgSaveNew"       runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,SaveRecord20%>" /> Save New</asp:LinkButton>  
                <asp:LinkButton ID="lbtDeleteDetail"  runat="server" CommandName="DeleteSelected"       ToolTip="Delete Group"                Visible='<%# rgvApplicationIdentifiers.EditIndexes.Count=0 and Not CType(Container, GridCommandItem).OwnerTableView.IsItemInserted %>'  OnClientClick="javascript:return confirm('You have selected to delete this user.<br>This process CANNOT BE UNDONE. <br> <br> Do you want to continue?')"> <asp:Image ID="imgDelete"        runat="server" CssClass="css_GFS01_Image_Align"  ImageURL="<%$ Resources:Images,DeleteRecord20%>" />Delete </asp:LinkButton>  
                <asp:LinkButton ID="lbtSaveDetail"    runat="server" CommandName="UpdateEdited"         ToolTip="Save Changes"                Visible='<%# rgvApplicationIdentifiers.EditIndexes.Count > 0 AND Not CType(Container, GridCommandItem).OwnerTableView.IsItemInserted %>'>                           <asp:Image ID="imgSave"          runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,SaveRecord20%>" />  Update </asp:LinkButton>  
                <asp:LinkButton ID="lbtFiltersDetail" runat="server" CommandName="ShowHideFiltersDetail"      style="position:absolute;left:770px;" ToolTip="Show/Hide Filters"           >                           <asp:Image ID="Image2" runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,Filter20%>" /> Show/Hide Filter</asp:LinkButton>  
                <asp:LinkButton ID="lbtRefreshDetail" runat="server" CommandName="RebindGridDetail"           style="position:absolute;Left:900px;" >                                                                                                                                         <asp:Image id="imgRefresh"       runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$Resources:Images, ReloadBlue20 %>"  />Refresh Grid</asp:LinkButton>                     
            </div>
        </CommandItemTemplate>
Item Command
Private Sub rgvApplicationIdentifiers_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgvApplicationIdentifiers.ItemCommand
  
        Select Case e.CommandName
            Case "ShowHideFilters"
                If rgvApplicationIdentifiers.AllowFilteringByColumn = True Then
                    rgvApplicationIdentifiers.AllowFilteringByColumn = False
                Else
                    rgvApplicationIdentifiers.AllowFilteringByColumn = True
                End If
                rgvApplicationIdentifiers.Rebind()
            Case "ShowHideFiltersDetail"
                Dim DetailView As GridTableView = DirectCast(e.Item.OwnerTableView, GridTableView)
                If DetailView.AllowFilteringByColumn = True Then
                    DetailView.AllowFilteringByColumn = False
                Else
                    DetailView.AllowFilteringByColumn = True
                End If
                DetailView.Rebind()
            Case "EditSelected"
                Dim TableView As GridTableView = DirectCast(e.Item.OwnerTableView, GridTableView)
                For Each GridItem As GridDataItem In TableView.Items
                    If GridItem.Selected Then
                        GridItem.Edit = True
                        flag1 = True
                    End If
                Next
                If flag1 Then
                    TableView.Rebind()
                    flag1 = False
                End If
  
            Case "EditSelectedDetail"
                Dim DetailView As GridTableView = DirectCast(e.Item.OwnerTableView, GridTableView)
                For Each item As GridDataItem In DetailView.Items
                    item.Edit = item.Selected
                Next
                DetailView.Rebind()
            Case "InitInsertDetail"
                Dim DetailView As GridTableView = DirectCast(e.Item.OwnerTableView, GridTableView)
                DetailView.IsItemInserted = True
                DetailView.Rebind()
            Case "RebindGrid"
                ViewState("FilterSecurityGroup") = "All"
                rgvApplicationIdentifiers.MasterTableView.FilterExpression = ""
                rgvApplicationIdentifiers.MasterTableView.Rebind()
  
        End Select
  
    End Sub
Update Command
Private Sub rgvApplicationIdentifiers_UpdateCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgvApplicationIdentifiers.UpdateCommand
        Dim EditedItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
        Dim strLevel1 As String = Nothing
        Dim strLevel2 As String = "Unassigned"
        Dim strLevel3 As String = "Unassigned"
        Dim strIdentifierCode As String = Nothing
        Dim intLevelNumber As Integer = 0
        Dim intTotalLevels As Integer = 0
        Dim bitShowInSort As Boolean = Nothing
        Dim bitUseIdentifierCode As Boolean = Nothing
        Dim bitActiveFlag As Boolean = Nothing
        Dim strLogonUser As String = Request.ServerVariables("AUTH_USER")
        Select Case e.Item.OwnerTableView.Name
            Case "Level1"
                strLevel1 = DirectCast(EditedItem("Level1Code").Controls(0), TextBox).Text
                intLevelNumber = 1
                intTotalLevels = DirectCast(EditedItem.FindControl("rcbTotalLevels"), RadComboBox).Text
                bitShowInSort = DirectCast(EditedItem("ShowInSort").Controls(0), CheckBox).Checked
                bitActiveFlag = DirectCast(EditedItem("ActiveFlag").Controls(0), CheckBox).Checked
                bitUseIdentifierCode = DirectCast(EditedItem("UseIdentifierCode").Controls(0), CheckBox).Checked
                Me.SQLDS_Level1.UpdateCommandType = SqlDataSourceCommandType.Text
                Me.SQLDS_Level1.UpdateCommand = "EXEC " + Me.hdfSource.Value + " 'Update', '" + strLevel1 + "', '" + strLevel2 + "', '" + strLevel3 + "', " + intLevelNumber.ToString + ", " + intTotalLevels.ToString + ", " + bitUseIdentifierCode.ToString + ", '" + strIdentifierCode + "', " + bitShowInSort.ToString + ", " + bitActiveFlag.ToString + ", '" + strLogonUser + "'"
            Case "Level2"
                strLevel1 = DirectCast(EditedItem("Level1CodeDetail").Controls(0), TextBox).Text
                strLevel2 = DirectCast(EditedItem("Level2CodeDetail").Controls(0), TextBox).Text
                strIdentifierCode = DirectCast(EditedItem("IdentifierCodeDetail").Controls(0), TextBox).Text
                intLevelNumber = 2
                bitShowInSort = DirectCast(EditedItem("ShowInSortDetail").Controls(0), CheckBox).Checked
                bitActiveFlag = DirectCast(EditedItem("ActiveFlagDetail").Controls(0), CheckBox).Checked
                bitUseIdentifierCode = DirectCast(EditedItem("UseIdentifierCodeDetail").Controls(0), CheckBox).Checked
                MsgBox("EXEC " + Me.hdfSource.Value + " 'Update', '" + strLevel1 + "', '" + strLevel2 + "', '" + strLevel3 + "', " + intLevelNumber.ToString + ", " + intTotalLevels.ToString + ", " + bitUseIdentifierCode.ToString + ", '" + strIdentifierCode + "', " + bitShowInSort.ToString + ", " + bitActiveFlag.ToString + ", '" + strLogonUser + "'")
                Me.SQLDS_Level2.UpdateCommandType = SqlDataSourceCommandType.Text
                Me.SQLDS_Level2.UpdateCommand = "EXEC " + Me.hdfSource.Value + " 'Update', '" + strLevel1 + "', '" + strLevel2 + "', '" + strLevel3 + "', " + intLevelNumber.ToString + ", " + intTotalLevels.ToString + ", " + bitUseIdentifierCode.ToString + ", '" + strIdentifierCode + "', " + bitShowInSort.ToString + ", " + bitActiveFlag.ToString + ", '" + strLogonUser + "'"
        End Select
    End Sub

Thank You
Tracy
0
Tracy
Top achievements
Rank 1
answered on 18 Mar 2011, 03:09 PM
Hi Princy,

Any thoughts on 2 questions?

Tracy
0
Princy
Top achievements
Rank 2
answered on 21 Mar 2011, 11:42 AM
Hello Tracy,

For the first scenario you can have different CommandName for Delete button in Master and DetailTable. Then you can write the delete query inside the event handler like below.
Vb.Net:
Protected Sub rgvApplicationIdentifiers_ItemCommand(sender As Object, e As GridCommandEventArgs)
    Dim tableview As GridTableView = DirectCast(e.Item.OwnerTableView, GridTableView)
    If e.CommandName = "DeleteSelectedMaster" Then
        For Each item As GridDataItem In tableview.Items
                    'write query for delete opeartion in master table
            If item.Selected Then
            End If
        Next
    End If
    If e.CommandName = "DeleteSelectedDetail" Then
 
        For Each item As GridDataItem In tableview.Items
                    'write query for delete opeartion in detail table
            If item.Selected Then
            End If
        Next
    End If
End Sub

And I haven't experienced the second issue. Please make sure that you have given appropriate CommndName for Update button in DetailTable.

Thanks,
Princy.
Tags
Grid
Asked by
Tracy
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Tracy
Top achievements
Rank 1
Share this question
or