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

Hide edit button of Child grid items

1 Answer 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
vivek
Top achievements
Rank 1
vivek asked on 03 Jan 2009, 05:45 AM
Hi I want to hide edit button of child grid item at run time for some specific roles............I am not getting how can i do that.......below is my grid design code..having yellow back n bold code is the button..

<telerik:RadGrid ID="grdExams"runat="server"DataSourceID="LinqDataSource1"

        AllowFilteringByColumn="True" AllowSorting="True" 

        AutoGenerateColumns="False" AllowPaging="True"

        Skin="Office2007" OnItemDataBound="grdExams_ItemDataBound"

        GridLines="None" AllowAutomaticDeletes="True"

        OnItemCommand="grdExams_ItemCommand" OnPreRender="grdExams_PreRender"

        GroupingEnabled="False" ondatabound="grdExams_DataBound"

        ondetailtabledatabind="grdExams_DetailTableDataBind"

        oninsertcommand="grdExams_InsertCommand"

        ondeletecommand="grdExams_DeleteCommand"

        onitemcreated="grdExams_ItemCreated" >

        <ClientSettings AllowDragToGroup="True" AllowExpandCollapse="true" AllowKeyboardNavigation="True">

            <Selecting AllowRowSelect="True" />

            <ClientEvents OnGridCreated="gridCreated" />

        </ClientSettings>

        <GroupPanel Visible="True">

        </GroupPanel>

        <MasterTableView GridLines="None" DataKeyNames="ID" DataSourceID="LinqDataSource1"

            CommandItemDisplay="TopAndBottom" Width="100%" Name="Examinations">

            <DetailTables>

                <telerik:GridTableView HierarchyLoadMode="Client" DataSourceID="LinqDataSource2" DataKeyNames="ID"

                    Width="100%" runat="server" EnableViewState="true" CommandItemDisplay="Bottom" AllowAutomaticDeletes="true"

                    AllowFilteringByColumn="false" Name="Detractions">

                    <ParentTableRelation>

                        <telerik:GridRelationFieldsMasterKeyField="ID"DetailKeyField="ExaminationID"/>

                    </ParentTableRelation>

                    <DetailTables>

                       <telerik:GridTableView DataKeyNames="ID" DataSourceID="LinqDataSource3"

Width="100%" runat="server">

                                <ParentTableRelation>

                                    <telerik:GridRelationFieldsDetailKeyField="ID"

 

MasterKeyField="ID" />

                                </ParentTableRelation>

<RowIndicatorColumn Visible="False">

<HeaderStyle Width="20px"></HeaderStyle>

</RowIndicatorColumn>

<ExpandCollapseColumn Visible="False" Resizable="False">

<HeaderStyle Width="20px"></HeaderStyle>

</ExpandCollapseColumn>

                                <Columns>

                                    <telerik:GridBoundColumn SortExpression="Remark"HeaderText="Remark"DataField="Remark"UniqueName="Remark"AllowFiltering="false">

                                    </telerik:GridBoundColumn> 

                                </Columns>

                             

<EditFormSettings>

<PopUpSettings ScrollBars="None"></PopUpSettings>

</EditFormSettings>

                             

                            </telerik:GridTableView>

                    </DetailTables>

                    <EditFormSettings>

                        <PopUpSettings ScrollBars="None"></PopUpSettings>

                    </EditFormSettings>

                    <CommandItemTemplate>

                        <div style="width: 100%; text-align:center">                           

                            <div style="float: right;padding: 5px; padding-right: 10px">

                                <asp:LinkButton ID="lnkRefreshDetraction" runat="server"CommandName="RefreshDetractions">

                                    <asp:Image ID="imgRefreshDetraction"runat="server"ImageAlign="AbsMiddle"ImageUrl="~/Images/radimg/Refresh.gif"

                                        AlternateText="AddDetractopm Record" />

                                    <asp:Label ID="lblRefreshDetraction"runat="server"Style="text-decoration:none;"

                                        Text=" Refresh DetractionList"></asp:Label>

                                </asp:LinkButton>

                            </div>

                             <div style="float: left;padding: 5px; padding-right: 10px">

                                <asp:LinkButton ID="LinkButton1"runat="server"CommandName="InitInsert">

                                    <asp:Image ID="Image1" runat="server"ImageAlign="AbsMiddle"ImageUrl="~/Images/AddRecord.gif"

                                        AlternateText="Add a newDetraction to the current record." />

                                    <asp:Label ID="Label1" runat="server"Style="text-decoration:none;" Text="Add Detraction...">

                                    </asp:Label>

                                </asp:LinkButton>

                            </div>

                        </div>

                    </CommandItemTemplate>

                    <RowIndicatorColumn Visible="False">

                        <HeaderStyle Width="20px"></HeaderStyle>

                    </RowIndicatorColumn>

                    <ExpandCollapseColumn Visible="False" Resizable="False">

                        <HeaderStyle Width="20px"></HeaderStyle>

                    </ExpandCollapseColumn>

                    <Columns>

                        <telerik:GridTemplateColumnUniqueName="TemplateDetractionEditColumn"AllowFiltering="false"

                            ShowSortIcon="false">

                            <ItemTemplate>

                                <asp:ImageButton ID="cmdDelete" runat="server" CommandName="Delete" OnClientClick="return confirm('Are you sure want to Delete?');"

                                    ImageUrl="~/Images/Delete.gif"/>

                                <asp:ImageButton ID="cmdEdit"runat="server"CommandName="Edit"ImageUrl="~/Images/Edit.gif"/>

                            </ItemTemplate>

                        </telerik:GridTemplateColumn>

                        <telerik:GridBoundColumn DataField="Severity"HeaderText="Severity"SortExpression="Severity"

                            UniqueName="Severity">

                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="DetractionType"HeaderText="Type"SortExpression="DetractionType"

                            UniqueName="DetractionType">

                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="DetractionSourceID"HeaderText="DetractionSourceID"ReadOnly="True"

                            SortExpression="DetractionSourceID"UniqueName="DetractionSourceID">

                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="DetractionSource"HeaderText="Source"ReadOnly="True"

                            SortExpression="DetractionSource"UniqueName="DetractionSource">

                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="TechnologistFault"DataType="System.Decimal"HeaderText="Technologist"

                            SortExpression="TechnologistFault"UniqueName="TechnologistFault">

                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="EquipmentFault"DataType="System.Decimal"HeaderText="Equipment"

                            SortExpression="EquipmentFault"UniqueName="EquipmentFault">

                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="PatientFault"DataType="System.Decimal"HeaderText="Patient"

                            SortExpression="PatientFault"UniqueName="PatientFault">

                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="ProcessFault"DataType="System.Decimal"HeaderText="Process"

                            SortExpression="ProcessFault"UniqueName="ProcessFault">

                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn Visible="false"DataField="DV"DataType="System.Decimal"HeaderText="DV"

                            SortExpression="DV"UniqueName="DV">

                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="ID"Visible="false"DataType="System.Int32"HeaderText="ID"

                            ReadOnly="True"SortExpression="ID"UniqueName="DetractionID">

                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn Visible="false"DataField="ExaminationID"DataType="System.Int32"

                            HeaderText="ExaminationID"SortExpression="ExaminationID"UniqueName="ExaminationID">

                        </telerik:GridBoundColumn>

                    </Columns>

                </telerik:GridTableView>

            </DetailTables>

            <RowIndicatorColumn Visible="False">

                <HeaderStyle Width="20px"></HeaderStyle>

            </RowIndicatorColumn>

            <ExpandCollapseColumn Visible="True" Resizable="False">

                <HeaderStyle Width="20px"></HeaderStyle>

            </ExpandCollapseColumn>

            <CommandItemTemplate>

                <div style="width: 100%; text-align: center">

                    <div style="float:left; padding:5px; padding-left:10px">

                        <asp:LinkButton ID="lnkAddRecord" runat="server" CommandName="InitInsert">

                            <div style="float:left;padding-left:5px">

                                <asp:Image ID="imgAddRecord"runat="server"ImageAlign="Top"ImageUrl="~/Images/Icons/24/ExamAdd.png"

                                    AlternateText="Add anExamination record" /></div>

                            <div style="float: left;padding-left: 5px; text-align: left; text-decoration: none;">

                                <asp:Label ID="lblAddRecord"runat="server"Text="Add<br/>Examination..."></asp:Label></div>

                        </asp:LinkButton>

                    </div>

                    <div style="float: left; padding: 5px; padding-left:10px">

                        <asp:LinkButton ID="lnkImportExams" runat="server" CommandName="ImportExams">

                            <div style="float: left;padding-left: 5px">

                                <asp:Image ID="imgImportExams"runat="server"ImageAlign="Top"ImageUrl="~/Images/Icons/24/Examimport.png"

                                    AlternateText="ImportExamination records" /></div>

                            <div style="float: left;padding-left: 5px; text-align: left; text-decoration: none;">

                                <asp:Label ID="lblImportExams"runat="server"Text="Import<br/>Examination Records...">

                                </asp:Label></div>

                        </asp:LinkButton>

                    </div>

                    <div style="float: right; padding: 5px; padding-right:10px">

                        <asp:LinkButton ID="lnkRefresh" runat="server" CommandName="RefreshExams">

                            <div style="float: left;padding-left: 5px">

                                <asp:Image ID="imgRefresh"runat="server"ImageAlign="Top"ImageUrl="~/Images/Icons/24/ExamRefresh.png"

                                    AlternateText="Refreshcurrent list of Examinations" /></div>

                            <div style="float: left;padding-left: 5px; text-align: left; text-decoration: none;">

                                <asp:Label ID="lblRefresh"runat="server"Text="Refresh<br />Examination List"></asp:Label></div>

                        </asp:LinkButton>

                    </div>

                </div>

            </CommandItemTemplate>

            <Columns>

                <telerik:GridTemplateColumn ItemStyle-Width="35px" UniqueName="TemplateEditColumn" AllowFiltering="false"ShowSortIcon="false">

                    <ItemTemplate>

                        <asp:ImageButton ID="cmdDelete" OnClientClick="return confirm('All records related to thisExamination will also be deleted. Are you sure?');"

                            runat="server"CommandName="Delete"ImageUrl="~/Images/Delete.gif"/>

                        <asp:ImageButton ID="cmdEdit" runat="server" CommandName="Edit" ImageUrl="~/Images/Edit.gif"/>

                    </ItemTemplate>

                <ItemStyle Width="35px"></ItemStyle>

                </telerik:GridTemplateColumn>

                <telerik:GridBoundColumn DataField="ID" DataType="System.Int32"

                    HeaderText="ID" SortExpression="ID" UniqueName="ID" ReadOnly="True" Visible="false">

                </telerik:GridBoundColumn>

                 <telerik:GridBoundColumn DataField="AccessionCode" HeaderText="Accession #"

                    SortExpression="AccessionCode" UniqueName="AccessionCode" ReadOnly="True">

                </telerik:GridBoundColumn>

                <telerik:GridBoundColumn DataField="ExaminationDate" HeaderText="Exam Date"

                    SortExpression="ExaminationDate" UniqueName="ExaminationDate"

                    DataType="System.DateTime" ReadOnly="True">

                </telerik:GridBoundColumn>

                  <telerik:GridBoundColumn DataField="Modality" HeaderText="Modality" SortExpression="Modality"

                    UniqueName="Modality" ReadOnly="True">

                    <ItemStyle Width="5px" />

                </telerik:GridBoundColumn>

                <telerik:GridBoundColumn DataField="ExaminationType"

                    HeaderText="Examin Type" SortExpression="ExaminationType"

                    UniqueName="ExaminationType" ReadOnly="True">

                    <ItemStyle Width="300px" />

                </telerik:GridBoundColumn>

              

             

                <telerik:GridBoundColumn DataField="ModalityID" Visible="false" >

               

                </telerik:GridBoundColumn>

                <telerik:GridBoundColumn DataField="Facility" HeaderText="Facility" SortExpression="Facility"

                    UniqueName="Facility" ReadOnly="True">

                </telerik:GridBoundColumn>

               

                  <telerik:GridBoundColumn

                    DataField="Technologist" HeaderText="Technologist" ReadOnly="True"

                    SortExpression="Technologist" UniqueName="Technologist">

                </telerik:GridBoundColumn>

               

                <telerik:GridTemplateColumn ItemStyle-Width="35px" DataField="DVSum" DataType="System.Decimal" HeaderText="DV"

                    SortExpression="DVSum" UniqueName="DVSum">

                 

                 

                    <ItemTemplate>

                        <asp:Label ID="DVSumLabel" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "DVSum") %>'></asp:Label>

                        &nbsp;

                        <asp:Image ID="imgSlight" runat="server" ImageAlign="absMiddle" ImageUrl="~/Images/icons/16/slight.gif" />

                        <asp:Image ID="imgModerate" runat="server" ImageAlign="absMiddle" ImageUrl="~/Images/icons/16/moderate.gif" />

                        <asp:Image ID="imgSevere" runat="server" ImageAlign="absMiddle" ImageUrl="~/Images/icons/16/severe.gif" />

                    </ItemTemplate>

                 

                </telerik:GridTemplateColumn>

             

            </Columns>

<EditFormSettings>

<PopUpSettings ScrollBars="None"></PopUpSettings>

</EditFormSettings>

        <PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>

        </MasterTableView>

        <ExportSettings>

            <Pdf PageBottomMargin="" PageFooterMargin="" PageHeaderMargin="" PageHeight="11in"

                PageLeftMargin="" PageRightMargin="" PageTopMargin="" PageWidth="8.5in" />

        </ExportSettings>

    </telerik:RadGrid>



can any body help me ....

Thanks,

Viv


I have tried with below code also but not hiding the buttons (also not throwing any error)

 protected void grdExams_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)

    {

        

        try

        {

            GridDataItemCollection Items = (GridDataItemCollection)e.DetailTableView.Items;

            foreach (GridDataItem Item in Items)

            {

                ImageButton ImageButtonDelete = (ImageButton)Item["TemplateDetractionEditColumn"].FindControl("cmdDelete");

                ImageButtonDelete.Visible = false;

                ImageButtonDelete.ToolTip = "dasdasdasdasdasdasdasdasd";

                

            }

        }

        catch (Exception ex)

        {

           

        }

    }

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Jan 2009, 05:30 AM
Hi Vivek,

Try accessing the the ImageButton in the ItemDataBound event as shown below. You can access the Detail table using its Name property.

CS:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if ((e.Item is GridDataItem) && (e.Item.OwnerTableView.Name == "Detractions")) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            ImageButton ImageButtonDelete = (ImageButton)item["TemplateDetractionEditColumn"].FindControl("cmdDelete"); 
            ImageButtonDelete.Visible = false
            ImageButtonDelete.ToolTip = "dasdasdasdasdasdasdasdasd"
        } 
        
    } 

Thanks
Shinu
Tags
Grid
Asked by
vivek
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or