Link Button In RadGrid Column.

7 posts, 0 answers
  1. Raja
    Raja avatar
    13 posts
    Member since:
    Oct 2011

    Posted 04 Oct 2011 Link to this post

    Can we have a Link Button in RadGrid Column,
    and LinkButton  on Click event to show DetailTable.... Can anybody help me in this issue. I need a clickable linkbutton in Radgrid column to show detailstable...
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Oct 2011 Link to this post

    Hello Raja,

    Try the following markup and codesnippet to have a LinkButton in RadGridColumn.
    aspx:
    <telerik:GridTemplateColumn>
       <ItemTemplate>
           <asp:LinkButton ID="LinkButton1" runat="server" Text="LinkButton" OnClick="HideDetail1_ShowDetail_Click">
             </
    asp:LinkButton>
       </ItemTemplate>
    </telerik:GridTemplateColumn>
    C#:
    rotected void HideDetail_ShowDetail1_Click(object sender, EventArgs e)
        {
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                RadGrid1.MasterTableView.Items[item.ItemIndex].ChildItem.NestedTableViews[0].Visible = false;
                RadGrid1.MasterTableView.Items[item.ItemIndex].ChildItem.NestedTableViews[1].Visible = true;
            }
         }
        protected void HideDetail1_ShowDetail_Click(object sender, EventArgs e)
        {
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                RadGrid1.MasterTableView.Items[item.ItemIndex].ChildItem.NestedTableViews[0].Visible = true;
                RadGrid1.MasterTableView.Items[item.ItemIndex].ChildItem.NestedTableViews[1].Visible = false;
            }
        }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Raja
    Raja avatar
    13 posts
    Member since:
    Oct 2011

    Posted 04 Oct 2011 Link to this post

    <telerik:RadGrid ID="Grid1" PagerStyle-Mode="NextPrevNumericAndAdvanced" Width="100%" AllowAutomaticInserts="false"    AllowAutomaticUpdates="false" PageSize="10" runat="server" PagerStyle-AlwaysVisible="true" OnDetailTableDataBind="Grid1_DetailTableDataBind"   AllowPaging="True" AllowSorting="True" Visible="false" GridLines="None" AllowFilteringByColumn="true" Skin="Office2007" AutoGenerateColumns="False" OnItemCommand="Grid1_ItemCommand"   OnItemDataBound="Grid1_ItemDataBound" ShowFooter="true">               
           <MasterTableView ShowFooter="true"  AllowAutomaticUpdates="false" DataKeyNames="row_id, Agency_code, Agency" TableLayout="Fixed" CommandItemDisplay="TopAndBottom" HierarchyLoadMode="Client">
           <DetailTables>
               <telerik:GridTableView CssClass="DetailTable" Name="RevenueNested" NoDetailRecordsText="No Records to display" ShowFooter="false"
                                        Width="1550px" AutoGenerateColumns="false" AllowFilteringByColumn="false" AllowPaging="false"
                                        AllowSorting="false" ToolTip="Click to View MOU\Payments"
                                        <ParentTableRelation>
                                            <telerik:GridRelationFields DetailKeyField="row_id" MasterKeyField="row_id" />
                                        </ParentTableRelation>                               
                                        <Columns>                                  
                                        <telerik:GridHyperLinkColumn  UniqueName="Attachments" HeaderStyle-Width="100px" Text="View MOU"  HeaderText="Attached MOU" DataNavigateUrlFields="URL" Target="_blank">                                  
                                        </telerik:GridHyperLinkColumn>                                                                                                                                     
                                        </Columns>                                  
               </telerik:GridTableView>
           </DetailTables>
                <Columns>
                <telerik:GridEditCommandColumn   UniqueName="EditCommandColumn" HeaderStyle-Width="50px">
                        </telerik:GridEditCommandColumn>
                                    <telerik:GridBoundColumn HeaderStyle-Width="130px" DataField="Agency_code" ItemStyle-HorizontalAlign="Left" HeaderText="Agency Code" UniqueName="Agency_code">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridTemplateColumn EditFormColumnIndex="1" FooterText="Total:" FooterStyle-HorizontalAlign="Right" AllowFiltering="true" UniqueName="agency" HeaderStyle-Width="300px" DataField="Agency" HeaderText="Agency">
                                        <ItemTemplate>            
                                            <asp:LinkButton ID="lnkViewMOU" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"Agency")%>' OnClick="HideDetail1_ShowDetail_Click"></asp:LinkButton>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>                   
                                    <telerik:GridBoundColumn Aggregate="Sum" HeaderStyle-Width="180px" FooterStyle-HorizontalAlign="Right" DataField="Total_Billing_Amount"
                                        DataFormatString="{0:c}" ItemStyle-HorizontalAlign="Right" HeaderText="Billed Budget" UniqueName="Total_Billing_Amount">
                                    </telerik:GridBoundColumn>
    </Columns>
    </MasterTableView>
            </telerik:RadGrid>

    Hey Prince Thanks for your quick response but it is not working in my case...
    protected void HideDetail1_ShowDetail_Click(object sender, EventArgs e)
        {
            foreach(GridDataItem item in RdWOListDCNET.MasterTableView.Items)
            {
                Grid1.MasterTableView.Items[item.ItemIndex].ChildItem.NestedTableViews[0].Visible = true;
                Grid1.MasterTableView.Items[item.ItemIndex].ChildItem.NestedTableViews[1].Visible = false;
            }
        }

    Its showing error on Line(Grid1.MasterTableView.Items[item.ItemIndex].ChildItem.NestedTableViews[1].Visible = false;) Index outside bounds of array
  5. Raja
    Raja avatar
    13 posts
    Member since:
    Oct 2011

    Posted 04 Oct 2011 Link to this post

    Hey Prince,
    I got part of it working with Java script, posted in your earlier forums but its only displaying the Details Table for the very first Item, am unable to pass the DataKeyName to the Java script.. Can you look into this please...
    function ExpandCollapseMasterTableViewItem()
          {
             var firstMasterTableViewRow = $find("<%= Grid1.MasterTableView.ClientID %>").get_dataItems()[0];
             if (firstMasterTableViewRow.get_expanded())
             {
                 firstMasterTableViewRow.set_expanded(false);
             }
             else
             {
                 firstMasterTableViewRow.set_expanded(true);
             }
         } 
       
     <telerik:GridTemplateColumn EditFormColumnIndex="1" FooterText="Total:" FooterStyle-HorizontalAlign="Right" AllowFiltering="true" UniqueName="agency" HeaderStyle-Width="300px" DataField="Agency" HeaderText="Agency">
                                        <ItemTemplate>              
                                            <asp:LinkButton ID="lnkViewMOU" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"Agency")%>' OnClientClick="ExpandCollapseMasterTableViewItem(); return false;"></asp:LinkButton>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>        
  6. Raja
    Raja avatar
    13 posts
    Member since:
    Oct 2011

    Posted 04 Oct 2011 Link to this post

    Hey Prince,

    protected void HideDetail1_ShowDetail_Click(object sender, EventArgs e)
        {
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                RadGrid1.MasterTableView.Items[item.ItemIndex].ChildItem.NestedTableViews[0].Visible = true;           
            }
        }

    This is not working in my Scenario, am I missing Something here....OnClick event is triggering but once it passes the logic, Details Table does not show Up...Can you help me please....
  7. Raja
    Raja avatar
    13 posts
    Member since:
    Oct 2011

    Posted 04 Oct 2011 Link to this post

    Hey Prince,

    I have a Grid1.Rebind(), and Databind() in Grid1_ItemCommand event...
    Does this mess up my DetailsTable Visibilty, because on LinkButton Event my page is Postingback though I have HierarchialMode ="Client"

    help needed very urgently..

    Thanks,
    Raja.
  8. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 11 Oct 2011 Link to this post

    Hello Raja,

    Try the following code snippet to expand the DetailTable by clicking the LinkButton.

    ASPX:
    <Columns>
      <telerik:GridTemplateColumn>
           <ItemTemplate>
              <asp:LinkButton ID="LinkButton5" OnClick="HideDetail_ShowDetail1_Click" runat="server">Hide Detail but Show Detail1</asp:LinkButton>
            </ItemTemplate>
       </telerik:GridTemplateColumn>
    </Columns>

    C#:
    protected void HideDetail_ShowDetail1_Click(object sender, EventArgs e)
    {
      LinkButton lbBtn = sender as LinkButton;
      GridDataItem item = (GridDataItem)(sender as LinkButton).NamingContainer;
      item.Expanded = true;
    }

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