Add How to add Button/LinkButton on the child table only in the "Hierarchy with templates"

6 posts, 1 answers
  1. Newkid
    Newkid avatar
    8 posts
    Member since:
    Aug 2012

    Posted 14 Mar 2012 Link to this post

    Hello,

    Could someone show me to add a button/hyperlink on the 2nd level?  I see you have the sample in the link below, but I only need to add  a button/hyperlink on the child table. 
    http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/threelevel/defaultcs.aspx

    Many Thanks!!!!

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

    Posted 15 Mar 2012 Link to this post

    Hello,

    The following code snippet shows how to add Button in Detail table . You can try adding a Button in GridTemplateColumn or can use GridButtonColumn for this purpose.
    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false">
      <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="CustomerID" HierarchyDefaultExpanded="true">
        <DetailTables>
          <telerik:GridTableView DataSourceID="SqlDataSource2" DataKeyNames="OrderID" runat="server" Name="DetailTable1">
            <ParentTableRelation>
              <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID" />
            </ParentTableRelation>
            <Columns>
              <telerik:GridButtonColumn UniqueName="GridButtonColumn1" ButtonType="PushButton" Text="GridButtonColumn1">
              </telerik:GridButtonColumn>
              <telerik:GridTemplateColumn UniqueName="Button" HeaderText="Button">
                <ItemTemplate>
                  <asp:Button ID="Button1" runat="server" Text="Button" />
                </ItemTemplate>
              </telerik:GridTemplateColumn>
            </Columns>
          </telerik:GridTableView>
        </DetailTables>
        <Columns>
          <telerik:GridBoundColumn UniqueName="CustomerID" HeaderText="CustomerID" DataField="CustomerID">
          </telerik:GridBoundColumn>
        </Columns>
      </MasterTableView>
    </telerik:RadGrid>


    Thanks,
    Princy.
  3. Newkid
    Newkid avatar
    8 posts
    Member since:
    Aug 2012

    Posted 15 Mar 2012 Link to this post

    Princy,
    Thanks for your reply.  I think i wasnot clear on my question.  What i want to display a "Add New Record" button (or link) under need of my child table (see my attached file).  When i click on this button/link, i will go to another page.  
    I have tried different way but i couldn't make it work.  Do you have any ideas?  Thanks so much!!!!
  4. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Mar 2012 Link to this post

    Hello,

    You can add a FooterTemplate in the GridTemplateColumn of the DetailTables. See the following code snippet.
    aspx:
    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false" >
      <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="ProjectID" HierarchyDefaultExpanded="true">
        <DetailTables>
          <telerik:GridTableView DataSourceID="SqlDataSource2" DataKeyNames="RequestStatus" runat="server" ShowFooter="true" Name="DetailTable1">
            <ParentTableRelation>
              <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="ProjectID" />
            </ParentTableRelation>
            <Columns>
              <telerik:GridBoundColumn UniqueName="RequestStatus" HeaderText="Request Status" DataField="RequestStatus" ></telerik:GridBoundColumn>
              <telerik:GridBoundColumn UniqueName="Reason" HeaderText="Reason" DataField="Reason" ></telerik:GridBoundColumn>
              <telerik:GridBoundColumn UniqueName="Other Reason" HeaderText="Other Reason" DataField="Other Reason" ></telerik:GridBoundColumn>
              <telerik:GridTemplateColumn >
                <FooterTemplate>
                  <asp:Button ID="Button1" runat="server" Text="Add New Record" />
                </FooterTemplate>
              </telerik:GridTemplateColumn>
            </Columns>
          </telerik:GridTableView>
        </DetailTables>
        <Columns>
          <telerik:GridBoundColumn UniqueName="ProjectID" HeaderText="Project ID" DataField="ProjectID"></telerik:GridBoundColumn>
          <telerik:GridBoundColumn UniqueName="prj_status" HeaderText="prj_status" DataField="prj_status"></telerik:GridBoundColumn>
          <telerik:GridBoundColumn UniqueName="Title" HeaderText="Title" DataField="Title"></telerik:GridBoundColumn>
        </Columns>
      </MasterTableView>
    </telerik:RadGrid>
    CSS:
    <style type="text/css">
      .RadGrid_Default .rgFooter td
        {
          float:left !important;
        }
    </style>
    Hope this helps.

    Thanks,
    Princy.
  5. Raj
    Raj avatar
    10 posts
    Member since:
    Mar 2012

    Posted 01 Apr 2012 Link to this post

    I am creating radgrid by programatically and i created CommandItemTemplate for AddNewRecord created,for that i need to assign the  blue  
    color for the link button, please let me know.

    Thanks,
    Raj
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Apr 2012 Link to this post

    Hello Raj,

    Try the following code to assigning color for linkbutton.
    C#:
    void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
     if (e.Item is GridCommandItem)
     {
       GridCommandItem item = (GridCommandItem)e.Item;
       LinkButton link = (LinkButton)item.FindControl("LinkButtonId");
       link.ForeColor = System.Drawing.Color.Blue;
     }
    }

    Thanks,
    Princy.
Back to Top