RadGrid Hide Label GridTemplateColumn

3 posts, 0 answers
  1. Allan
    Allan avatar
    121 posts
    Member since:
    Jun 2008

    Posted 24 Aug 2012 Link to this post

    I am having an issue hiding a label in a GridTemplateColumn.

    Here is my grid:
    <telerik:RadGrid ID="rgd_User_List" runat="server" AllowSorting="True"
        DataSourceID="sds_User_Lookup" GridLines="None" AllowPaging="True" PageSize="200">
        <ClientSettings
            AllowColumnsReorder="True" ReorderColumnsOnClient="True">
        </ClientSettings>
        <PagerStyle
            Mode="NextPrevAndNumeric" AlwaysVisible="true" HorizontalAlign="Center" Position="TopAndBottom">
        </PagerStyle>
        <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Top" DataKeyNames="IDStaff" DataSourceID="sds_User_Lookup">
            <CommandItemSettings ExportToPdfText="Export to Pdf"
                ShowAddNewRecordButton="False" ShowExportToCsvButton="True"
                ShowRefreshButton="False" />
            <RowIndicatorColumn>
                <HeaderStyle Width="20px" />
            </RowIndicatorColumn>
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px" />
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridTemplateColumn DefaultInsertValue="" HeaderText=" "
                    UniqueName="TemplateColumn1">
                    <itemtemplate>
                        <%# Container.ItemIndex+1 %>
                        </itemtemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name"
                    SortExpression="LastName" UniqueName="LastName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name"
                    SortExpression="FirstName" UniqueName="FirstName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="IDStaff" HeaderText="Staff ID"
                    SortExpression="IDStaff" UniqueName="IDStaff">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="IDBitech" HeaderText="BiTech ID"
                    SortExpression="IDBitech" UniqueName="IDBitech">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="UserName" HeaderText="User Name"
                    SortExpression="UserName" UniqueName="UserName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Password" HeaderText="Password"
                    SortExpression="Password" UniqueName="Password">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="JobTitle" HeaderText="Job Title"
                    SortExpression="JobTitle" UniqueName="JobTitle">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="PhoneIP" HeaderText="IP Phone"
                    SortExpression="PhoneIP" UniqueName="PhoneIP">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn DataField="Restraints" HeaderText="Restraints"
                    SortExpression="Restraints" UniqueName="Restraints">
                    <ItemTemplate>
                        <asp:Label ID="RestraintsLabel" runat="server" Text='<%# Eval("Restraints") %>'></asp:Label>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridHyperLinkColumn DataNavigateUrlFields="UserName"
                    DataNavigateUrlFormatString="user_details.aspx?UserName={0}" Text="Details"
                    UniqueName="UserName">
                    <ItemStyle CssClass="radgrid" />
                </telerik:GridHyperLinkColumn>
                <telerik:GridHyperLinkColumn AllowFiltering="False"
                    DataNavigateUrlFields="EmailAddress" DataNavigateUrlFormatString="mailto:{0}"
                    HeaderText=" " ItemStyle-HorizontalAlign="Center" UniqueName="EmailAddress">
                    <ItemStyle CssClass="radgrid" Width="50px" />
                </telerik:GridHyperLinkColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
    Here is my code:

    Protected Sub rgd_User_List_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles rgd_User_List.ItemDataBound
     
        If TypeOf e.Item Is GridDataItem Then
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim value As String = item("Restraints").Text
            If value = "1" Then
                Dim Restraints As Label = DirectCast(item("RestraintsLabel").Controls(0), Label)
                Restraints.Visible = False
            End If
        End If
     
    End Sub


    Any help appreciated.
  2. Allan
    Allan avatar
    121 posts
    Member since:
    Jun 2008

    Posted 24 Aug 2012 Link to this post

    RESOLVED


    <telerik:RadGrid ID="rgd_User_List" runat="server" AllowSorting="True"
        DataSourceID="sds_User_Lookup" GridLines="None" AllowPaging="True" PageSize="200">
        <ClientSettings
            AllowColumnsReorder="True" ReorderColumnsOnClient="True">
        </ClientSettings>
        <PagerStyle
            Mode="NextPrevAndNumeric" AlwaysVisible="true" HorizontalAlign="Center" Position="TopAndBottom">
        </PagerStyle>
        <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Top" DataKeyNames="IDStaff, Restraints, Password" DataSourceID="sds_User_Lookup">
            <CommandItemSettings ExportToPdfText="Export to Pdf"
                ShowAddNewRecordButton="False" ShowExportToCsvButton="True"
                ShowRefreshButton="False" />
            <RowIndicatorColumn>
                <HeaderStyle Width="20px" />
            </RowIndicatorColumn>
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px" />
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridTemplateColumn DefaultInsertValue="" HeaderText=" "
                    UniqueName="TemplateColumn1">
                    <itemtemplate>
                        <%# Container.ItemIndex+1 %>
                        </itemtemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name"
                    SortExpression="LastName" UniqueName="LastName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name"
                    SortExpression="FirstName" UniqueName="FirstName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="IDStaff" HeaderText="Staff ID"
                    SortExpression="IDStaff" UniqueName="IDStaff">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="IDBitech" HeaderText="BiTech ID"
                    SortExpression="IDBitech" UniqueName="IDBitech">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="UserName" HeaderText="User Name"
                    SortExpression="UserName" UniqueName="UserName">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn DataField="Password" HeaderText="Password"
                    SortExpression="Password" UniqueName="Password">
                    <ItemTemplate>
                        <asp:Label ID="Password" runat="server" Text='<%# Eval("Password") %>'></asp:Label>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="JobTitle" HeaderText="Job Title"
                    SortExpression="JobTitle" UniqueName="JobTitle">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="PhoneIP" HeaderText="IP Phone"
                    SortExpression="PhoneIP" UniqueName="PhoneIP">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn DataField="Restraints" HeaderText="Restraints"
                    SortExpression="Restraints" UniqueName="Restraints" Visible="False">
                    <ItemTemplate>
                        <asp:Label ID="Restraints" runat="server" Text='<%# Eval("Restraints") %>'></asp:Label>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridHyperLinkColumn DataNavigateUrlFields="UserName"
                    DataNavigateUrlFormatString="user_details.aspx?UserName={0}" Text="Details"
                    UniqueName="UserName">
                    <ItemStyle CssClass="radgrid" />
                </telerik:GridHyperLinkColumn>
                <telerik:GridHyperLinkColumn AllowFiltering="False"
                    DataNavigateUrlFields="EmailAddress" DataNavigateUrlFormatString="mailto:{0}"
                    HeaderText=" " ItemStyle-HorizontalAlign="Center" UniqueName="EmailAddress">
                    <ItemStyle CssClass="radgrid" Width="50px" />
                </telerik:GridHyperLinkColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>


    Protected Sub rgd_User_List_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles rgd_User_List.ItemDataBound
     
        If TypeOf e.Item Is GridDataItem Then
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim Restraint As String = DirectCast(item.FindControl("Restraints"), Label).Text
     
            If Restraint Like "Confidential" Then
                Dim Password As Label = DirectCast(item.FindControl("Password"), Label)
                Password.Visible = False
            End If
     
        End If
     
    End Sub



  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 24 Aug 2012 Link to this post

    Hello,

    Please try with below code snippet.

    Protected Sub rgd_User_List_ItemDataBound(sender As Object, e As GridItemEventArgs)
        If TypeOf e.Item Is GridDataItem Then
            Dim item As GridDataItem = TryCast(e.Item, GridDataItem)
            Dim RestraintsLabel As Label = TryCast(item.FindControl("RestraintsLabel"), Label)
            If RestraintsLabel IsNot Nothing Then
                RestraintsLabel.Visible = False
            End If
        End If
    End Sub


    Thanks,
    Jayesh Goyani
Back to Top