RadTreeList with nested RadGrid in TemplateColumn

2 posts, 0 answers
  1. Chrisbarm
    Chrisbarm avatar
    5 posts
    Member since:
    Nov 2008

    Posted 04 Jun 2015 Link to this post

    HI,

    I have a hierarchical RadTreeList using TreeListTemplateColumns - in one of these template columns I have a label (hidden) and a RadGrid,  the purpose of the Label is to make available an ID to use to bind the RadGrid.  

    If I try to put this ID into either the ParentDataKeyNames, DataKeyNames or both the treelist does not display, this is why it is in a label.

    I am trying to use the OnNeedDataSource Event of the RadGrid to bind the data to it, however I cannot find / get the value from the label.

    I have tried TreeListDataItem Item = (TreeListDataItem)(grid.NamingContainer); to reference the column but I just cant seem to get it right.  

    01.<telerik:TreeListTemplateColumn UniqueName="Firmware" HeaderText="Firmware">
    02.    <ItemTemplate>
    03.        <asp:Label ID="lblPartNumberDetailsId" runat="server" Text='<%#Eval("PartNumberDetails_Id") %>' Visible="false" />
    04. 
    05.          <telerik:RadGrid ID="RGFirmware" runat="server" Visible="true" AutoGenerateColumns="false" ShowHeader="false" ShowFooter="false"
    06.            MasterTableView-EditMode="InPlace" AllowAutomaticInserts="true" OnNeedDataSource="RGFirmware_NeedDataSource" OnInsertCommand="RGFirmware_InsertCommand">
    07.            <MasterTableView CommandItemDisplay="bottom">
    08.                <CommandItemSettings AddNewRecordText="Add Firmware" ShowAddNewRecordButton="false" ShowRefreshButton="false" />
    09.                <CommandItemTemplate>
    10.                    <asp:LinkButton ID="AddFirmware" runat="server" Text="Add Firmware" CommandName="InitInsert" />
    11.                </CommandItemTemplate>
    12.                <NoRecordsTemplate></NoRecordsTemplate>
    13.                <Columns>
    14.                    <telerik:GridTemplateColumn UniqueName="FirmWare">
    15.                        <ItemTemplate>
    16.                            <asp:TextBox ID="txtFirmware" runat="server" Text='<%#Eval("FirmWare") %>' />
    17. 
    18.                        </ItemTemplate>
    19.                        <EditItemTemplate>
    20.                            <asp:TextBox ID="txtFirmware" runat="server" Text='<%#Eval("FirmWare") %>' />
    21. 
    22.                        </EditItemTemplate>
    23.                    </telerik:GridTemplateColumn>
    24.                </Columns>
    25.            </MasterTableView>
    26.        </telerik:RadGrid
    27.    </ItemTemplate>
    28.</telerik:TreeListTemplateColumn>

     

    01.protected void RGFirmware_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    02.{
    03.    RadGrid grid = sender as RadGrid;
    04.    TreeListDataItem item = (TreeListDataItem)(grid.NamingContainer);
    05.    string Value = ((Label)item["PartNumberDetails_Id"].FindControl("lblPartNumberDetailsId")).Text.ToString();
    06. 
    07.    if (!String.IsNullOrEmpty(Value))
    08.    {
    09.        DataTable objDT = new DataTable("TempTable");
    10.        List<SqlParameter> parameters = new List<SqlParameter>();
    11.        parameters.Add(new SqlParameter("@PartNumberDetailsId", Value));
    12.        objDT = DataAccess.BuildDataTable("SelectFirmwareForPart", parameters);
    13.        grid.DataSource = objDT;
    14.    }
    15.    else
    16.    {
    17.        grid.Visible = false;
    18.    }
    19.}

     

    Any help is much appreciated

    Chris

  2. Chrisbarm
    Chrisbarm avatar
    5 posts
    Member since:
    Nov 2008

    Posted 04 Jun 2015 in reply to Chrisbarm Link to this post

    Sorry the line 

     05.   string Value = ((Label)item["PartNumberDetails_Id"].FindControl("lblPartNumberDetailsId")).Text.ToString();

    should read

    05.   string Value = ((Label)item["Firmware"].FindControl("lblPartNumberDetailsId")).Text.ToString();

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