Hide cell content based on condition

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

    Posted 09 Mar 2010 Link to this post

    Hello,

    I am using Version=2009.3.1208.35 and programming in asp.net vb.

    I have a RadGrid bound to a SQL Data Source.

    I would like to be able to hide the cell content of a GridHyperLinkColumn if the value in a field is not empty or not null.

    Here is my ASPX code.

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="employee.aspx.vb" Inherits="cf_console_admin_profiles_employee_employee" %> 
     
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
     
    <%@ Register assembly="Telerik.Web.UI, Version=2009.3.1208.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head id="Head1" runat="server">  
        <title>Fleet Compliance Management System</title> 
        <link rel="stylesheet" type="text/css" href="http://cf.visionquestit.net/includes/styles/cf_style.css"/>  
    </head> 
    <body> 
    <form id="form1" runat="server">  
         
              
    <table id="tablePageBodyContainer" class="tablePageBodyContainer">  
        <tr> 
            <td> 
            <table id="tablePageHeader" class="tablePageHeader">  
                <tr> 
                    <td class="tablePageHeaderColumn">  
                        <div class="divPageHeader">  
                            <span class="spanLoginTitle">  
                            Logged In  
                            </span><br/>  
                            <span class="spanLoginUserName">  
                            <%Response.Write(Session("x_Firstname"))%> 
                            </span> 
                            <span class="spanLoginUserName">  
                            <%Response.Write(Session("x_Lastname"))%> 
                            </span> 
                        </div> 
                    </td> 
                </tr> 
            </table> 
            <table id="tablePageBody" class="tablePageBody">  
            <tr> 
                <td class="tablePageBodyLeftColumn">  
                    <telerik:RadPanelBar ID="RadPanelBar1" Runat="server" DataFieldID="DataFieldID"   
                        DataFieldParentID="DataFieldParentID"   
                        DataNavigateUrlField="DataNavigateUrlField" DataSourceID="SqlDataSource1"   
                        DataTextField="DataTextField" DataValueField="DataTextField" Height="100%"   
                        Skin="Forest" Width="180px" ExpandMode="FullExpandedItem"   
                        PersistStateInCookie="True">  
                    </telerik:RadPanelBar> 
                <asp:SqlDataSource ID="SqlDataSource1" runat="server"   
            ConnectionString="<%$ ConnectionStrings:CF_SQL_Connection %>"   
            SelectCommand="SELECT [DataFieldID], [DataFieldParentID], [DataTextField], [DataNavigateUrlField], [ImageURL] FROM [CF_Menu_Console]">  
        </asp:SqlDataSource> 
        <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">  
        </telerik:RadScriptManager> 
                </td> 
                <td class="tablePageBodyRightColumn">  
                    <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True"   
                        DataSourceID="sdsEmployeeList" GridLines="None" Skin="Telerik"   
                        Width="771px">  
                        <mastertableview autogeneratecolumns="False" datasourceid="sdsEmployeeList">  
                            <rowindicatorcolumn> 
                                <HeaderStyle Width="20px" /> 
                            </rowindicatorcolumn> 
                            <expandcollapsecolumn> 
                                <HeaderStyle Width="20px" /> 
                            </expandcollapsecolumn> 
                            <Columns> 
                                <telerik:GridHyperLinkColumn DataNavigateUrlFields="FirstName,IDProfileEmployee"   
                                    DataNavigateUrlFormatString="employeedetails.aspx?IDProfileEmployee={1}"   
                                    DataTextField="IDProfileEmployee" DataTextFormatString="Details"   
                                    Text="View" UniqueName="View">  
                                    <ItemStyle Width="50px" /> 
                                </telerik:GridHyperLinkColumn> 
                                <telerik:GridBoundColumn DataField="LastName" HeaderText="LastName"   
                                    SortExpression="LastName" UniqueName="LastName">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName"   
                                    SortExpression="FirstName" UniqueName="FirstName">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="Email" HeaderText="Email"   
                                    SortExpression="Email" UniqueName="Email">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridHyperLinkColumn DataNavigateUrlFields="IDProfileEmployee,FirstName,LastName"   
                                    DataNavigateUrlFormatString="../../../../includes/makeuser.aspx?IDProfileEmployee={0}&amp;FirstName={1}&amp;LastName={2}"   
                                    Text="User" UniqueName="AddUser">  
                                </telerik:GridHyperLinkColumn> 
                            </Columns> 
                        </mastertableview> 
                    </telerik:RadGrid> 
                    <asp:SqlDataSource ID="sdsEmployeeList" runat="server"   
                        ConnectionString="<%$ ConnectionStrings:CF_SQL_Connection %>"   
                        SelectCommand="SELECT [IDProfileEmployee], [IDUser], [LastName], [FirstName], [Email] FROM [CF_Profile_Employee]">  
                    </asp:SqlDataSource> 
                </td> 
           </table>           
          
    </table> 
          
              
        <table class="tablePageFooter">  
            <tr> 
                <td> 
                    <!--#include virtual ="/includes/footer.htm" --></td>  
            </tr> 
        </table> 
        </form> 
    </body> 
    </html> 
     

    Here is my code behind:

     
    Imports Telerik.Web.UI  
     
    Partial Class cf_console_admin_profiles_employee_employee  
        Inherits System.Web.UI.Page  
     
     
        Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs)  
            If TypeOf e.Item Is GridDataItem Then  
                Dim item As GridDataItem = TryCast(e.Item, GridDataItem)  
                Dim textBox As TextBox = TryCast(item.FindControl("AddUser"), TextBox)  
                If textBox.Text.Length > 0 Then  
                    Dim commandItem As GridCommandItem = TryCast(TryCast(sender, RadGrid).MasterTableView.GetItems(GridItemType.CommandItem)(0), GridCommandItem)  
                    TryCast(commandItem.FindControl("AddUser"), TextBox).Visible = False 
                End If  
            End If  
        End Sub  
     
    End Class  
     

    Thank you in advance.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Mar 2010 Link to this post

    Hi Allan,

    The following code snippet shows how to hide the hyperlink if the value in FirstName column is not null.

    VB:

     
    Protected Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As GridItemEventArgs)  
        If TypeOf e.Item Is GridDataItem Then  
            Dim item As GridDataItem = TryCast(e.Item, GridDataItem)  
            Dim value As String = item("FirstName").Text  
            If value <> " " Then  
                Dim hLink As HyperLink = DirectCast(item("AddUser").Controls(0), HyperLink)  
                hLink.Visible = False  
            End If  
        End If  
    End Sub 

    Hope this helps,

    Shinu.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Allan
    Allan avatar
    121 posts
    Member since:
    Jun 2008

    Posted 10 Mar 2010 Link to this post

    Shinu,

    Thank you for such a quick and usefull response.

    Allan
Back to Top