toggle visibility of buttons in RadGrid

2 posts, 0 answers
  1. James O'Brien
    James O'Brien avatar
    19 posts
    Member since:
    Oct 2009

    Posted 06 Aug 2010 Link to this post

    Hi,

    I have an asp:LinkButton inside of my grid. I need this button to be invisible when the user is not logged in and visible when logged in. The problem I'm having is that I'm not sure how to access this button's ID to control it.

    here is my code:

    <telerik:RadGrid ID="gridEventsWebinars" runat="server" AutoGenerateColumns="false"
                        ShowHeader="false" EnableEmbeddedSkins="False" OnNeedDataSource="gridEventsWebinars_NeedDataSource"
                        OnColumnCreated="gridEventsWebinars_ColumnCreated" OnItemCreated="gridEventsWebinars_ItemCreated"
                          OnItemCommand="RadGrid_ItemCommand">
                        <HeaderContextMenu EnableEmbeddedSkins="False">
                        </HeaderContextMenu>
                        <MasterTableView DataKeyNames="strCampaignID">
                            <GroupByExpressions>
                                <telerik:GridGroupByExpression>
                                    <SelectFields>
                                        <telerik:GridGroupByField FieldName="strStartMonth" FormatString="{0:MMMM}" HeaderText=" "
                                            HeaderValueSeparator=" " />
                                    </SelectFields>
                                    <GroupByFields>
                                        <telerik:GridGroupByField FieldName="intStartMonth" HeaderText=" " SortOrder="Ascending" />
                                    </GroupByFields>
                                </telerik:GridGroupByExpression>
                            </GroupByExpressions>
                            <Columns>
                                <telerik:GridTemplateColumn UniqueName="WebinarID">
                                    <ItemTemplate>
                                        <div style="clear: both;">
                                            <div style="float: left;">
                                                <asp:Image ID="imgWebinar" runat="server" ImageUrl="~/img/WebinarIcon24.jpg" ToolTip='<%# Eval("strEventName") %>' /></div>
                                            <div style="position: relative; padding-left: 36px;">
                                                <p>
                                                    <asp:Label ID="lblStartDate" runat="server" Text='<%# Eval("dtStartDate", "{0:M/dd/yyyy}") %>'></asp:Label>
                                                    |
                                                    <asp:Label ID="lblStartTime" runat="server" Text='<%# Eval("dtStartTime", "{0:h:mm tt}") %>'></asp:Label>
                                                    
                                                    <asp:Label ID="lblEndTime" runat="server" Text='<%# Eval("dtEndTime", "{0:h:mm tt}") %>'></asp:Label>
                                                    ET
                                                    <br />
                                                    <strong>
                                                        <asp:Label ID="lblEventType" runat="server" Text='<%# Eval("strEventType") %>'></asp:Label>
                                                        | </strong><strong>
                                                            <asp:Label ID="lblEventName" runat="server" Text='<%# Eval("strEventName") %>'></asp:Label></strong>
                                                    <!-- KK on 05.05.09 -->
                                                    <!-- Added description to Webinar listing -->
                                                    <br />
                                                    <asp:Label ID="lblDescription" runat="server" Text='<%# Eval("strDescription") %>'></asp:Label>
                                                    <br />
                                                    <!-- JO on 12.16.08 -->
                                                    <!-- Added functionally on turn off sign-up -->
                                                    <%--<asp:HyperLink ID="linkSignUp" runat="server" NavigateUrl='<%# "~/Contact/webinar-signup.aspx?EventID=" + Eval("intEventID") %>'>Learn More & Register</asp:HyperLink>--%>
                                                    <asp:HyperLink ID="linkSignUp" runat="server" NavigateUrl='<%# "EventDetail.aspx?EventID=" + Eval("intEventID") %>'>Learn More</asp:HyperLink>
                                                           
                                                     
                                                    <asp:LinkButton ID="RegisterWebinarBtn" runat="server" Text="One-click Registration" CommandName="RegisterWebinarBtn_Command"></asp:LinkButton>
                                                     
                                                     
                                                </p>
                                            </div>
                                        </div>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                            </Columns>
                            <EditFormSettings>
                                <EditColumn InsertImageUrl="Update.gif" UpdateImageUrl="Update.gif" EditImageUrl="Edit.gif"
                                    CancelImageUrl="Cancel.gif">
                                </EditColumn>
                            </EditFormSettings>
                        </MasterTableView>
                        <GroupHeaderItemStyle Font-Bold="True" Height="30px" CssClass="rgGroupHeader-events" />
                        <ClientSettings AllowExpandCollapse="False" AllowGroupExpandCollapse="False">
                            <Resizing AllowColumnResize="True" />
                        </ClientSettings>
                        <FilterMenu EnableEmbeddedSkins="False">
                        </FilterMenu>
                    </telerik:RadGrid>

    the button is:
    <asp:LinkButton ID="RegisterWebinarBtn" runat="server" Text="One-click Registration" CommandName="RegisterWebinarBtn_Command"></asp:LinkButton>

    Thanks
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Aug 2010 Link to this post

    Hello James,

    You can access the LinkButton control by using its Id and  FindControl method like below.

    C#:
    if(//the user not logged in)
     {
       if (e.Item is GridDataItem)
        {
          GridDataItem item=(GridDataItem)e.Item;
          LinkButton btn = (LinkButton)item.FindControl("RegisterWebinarBtn"); // access the LinkButton
          btn.Visible = false;
        }
     }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top