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

RadGrid Hide Label GridTemplateColumn

2 Answers 277 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 2
Allan asked on 24 Aug 2012, 02:45 PM
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 Answers, 1 is accepted

Sort by
0
Allan
Top achievements
Rank 2
answered on 24 Aug 2012, 05:01 PM
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



0
Jayesh Goyani
Top achievements
Rank 2
answered on 24 Aug 2012, 05:01 PM
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
Tags
Grid
Asked by
Allan
Top achievements
Rank 2
Answers by
Allan
Top achievements
Rank 2
Jayesh Goyani
Top achievements
Rank 2
Share this question
or