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

toggle visibility of buttons in RadGrid

1 Answer 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James O'Brien
Top achievements
Rank 1
James O'Brien asked on 06 Aug 2010, 09:30 PM
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

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Aug 2010, 06:07 AM
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.
Tags
Grid
Asked by
James O'Brien
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or