Get TreeList Column Value - ItemCreated

6 posts, 0 answers
  1. William
    William  avatar
    72 posts
    Member since:
    Jun 2011

    Posted 08 Mar 2012 Link to this post

    I am trying to set the attributes of an edit hyperlink in a TreeList. When you click the edit hyperlink it will execute javascript to open a RadWindow. What I would like to do is to pass the "Req #" column value when you click the hyperlink. I thought the best way would be to write that value in the onclick attribute on each hyperlink created. Although I'm having trouble getting the associated "Req #" column value.

    To make it easier to understand I have attached an image. Basically I want pass the "Req #" value to the RadWindow when the "view/edit" link is clicked. 

    Below is my code:

    ASPX

    <telerik:RadAjaxLoadingPanel ID="replenishmentLoadingPanel" runat="server" Skin="Simple" />
            <telerik:RadTabStrip ID="replenishmentTabStrip" runat="server" Skin="Simple" MultiPageID="RadMultiPage2"
                SelectedIndex="0">
                <Tabs>
                    <telerik:RadTab Text="Req">
                    </telerik:RadTab>
                    <telerik:RadTab Text="P.O.">
                    </telerik:RadTab>
                </Tabs>
            </telerik:RadTabStrip>
            <telerik:RadMultiPage ID="RadMultiPage2" runat="server" SelectedIndex="0" >
                <telerik:RadPageView ID="replenishmentPageView1" runat="server">
                    <telerik:RadTreeList ID="requisitionTreeList" runat="server" AutoGenerateColumns="false" AllowSorting="false" AllowPaging="false"
                      OnNeedDataSource="requistions_needdata" OnPreRender="replenishment_PreRender" OnItemCreated="requisitons_ItemCreated"
                      DataKeyNames="ID" ParentDataKeyNames="PID" ShowTreeLines="false" EditMode="PopUp" >
                        <Columns>
                            <telerik:TreeListEditCommandColumn ShowEditButton="false" AddRecordText="Add" HeaderStyle-Width="30px" />
                            <telerik:TreeListBoundColumn DataField="ID" Visible="false" />
                            <telerik:TreeListBoundColumn DataField="PID" Visible="false" />
                            <telerik:TreeListBoundColumn DataField="ReqNum" HeaderText="Req #" UniqueName="ReqNum" />
                            <telerik:TreeListBoundColumn DataField="PONumber" HeaderText="PO #" />
                            <telerik:TreeListBoundColumn DataField="ReqDateTime" HeaderText="Transmit Time" />
                            <telerik:TreeListTemplateColumn UniqueName="TemplateEditColumn">
                                <ItemTemplate>
                                    <asp:HyperLink ID="EditLink" runat="server" Text="View/Edit" href="#" onclick="openRadWin();"></asp:HyperLink>
                                </ItemTemplate>
                            </telerik:TreeListTemplateColumn>
                        </Columns>
                    </telerik:RadTreeList>
                     
                </telerik:RadPageView>
     
                <telerik:RadPageView ID="repenishmentPageView2" runat="server">
                    <telerik:RadTreeList ID="purchaseorderTreeList" runat="server" AutoGenerateColumns="false" AllowSorting="false" AllowPaging="false"
                      OnNeedDataSource="purchaseOrders_needdata" DataKeyNames="ID" ParentDataKeyNames="PID" ShowTreeLines="false" EditMode="PopUp" >
                        <Columns>
                            <telerik:TreeListEditCommandColumn ShowEditButton="false" AddRecordText="Add" HeaderStyle-Width="50px" />
                            <telerik:TreeListBoundColumn DataField="ID" Visible="false" />
                            <telerik:TreeListBoundColumn DataField="PID" Visible="false" />
                            <telerik:TreeListBoundColumn DataField="PONumber" HeaderText="PO #" />
                            <telerik:TreeListBoundColumn DataField="ReqNum" HeaderText="Req #" />
                            <telerik:TreeListBoundColumn DataField="PODateTime" HeaderText="Transmit Time" />
                        </Columns>
                    </telerik:RadTreeList>
                </telerik:RadPageView>
            </telerik:RadMultiPage>


    C#

    protected void requisitons_ItemCreated(object sender, TreeListItemCreatedEventArgs e)
           {
               if (e.Item is TreeListDataItem)
               {     
                   HyperLink editLink = (HyperLink)e.Item.FindControl("EditLink");
                   editLink.Attributes["href"] = "#";
                   //editLink.Attributes["onclick"] = "openRadWin(" + value + ");";
               }
           }


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

    Posted 09 Mar 2012 Link to this post

    Hello,

    Access the data item inside ItemDataBound event. Try the following to access the column value.
    C#:
    protected void RadTreeList1_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
     {
      if (e.Item is TreeListDataItem)
       {
        TreeListDataItem dataItem = e.Item as TreeListDataItem;
        HyperLink editLink = (HyperLink)e.Item.FindControl("EditLink");
        editLink.Attributes["href"] = "#";
        TableCell cell = dataItem["id"];
        string value = cell.Text;
        editLink.Attributes["onclick"] = "openRadWin(" + value + ");";
       }
     }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. William
    William  avatar
    72 posts
    Member since:
    Jun 2011

    Posted 09 Mar 2012 Link to this post

    It's returning "&nbsp;" for the text value. Although if I expand into the data item I can see the data I would like to retrieve; I'm just not sure how to get it. See the attached image.
  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 14 Mar 2012 Link to this post

    Hello William ,

    Could I kindly ask you to open regular support ticket and send us runnable version of your application. Thus we will be able to debug it locally and do our best to apply the needed modifications in order to have your requirements covered.

    Greetings,
    Maria Ilieva
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. William
    William  avatar
    72 posts
    Member since:
    Jun 2011

    Posted 14 Mar 2012 Link to this post

    Due to privacy restrictions I can't send you the application, and extracting just this piece may prove to be difficult. Although I have done some digging and I have found that all of the cells are blank during the ItemCreated event, although the cells are populated with data during the PreRender event. I can in fact view the data during the ItemCreated event, it's a List attached to the DataItem. I'm not sure if there is any way to access it. 
  7. William
    William  avatar
    72 posts
    Member since:
    Jun 2011

    Posted 14 Mar 2012 Link to this post

    Alright I figured it out. I just cast the DataItem as my List Class and then I was able to access the values.

    TreeListEditableItem edataitem = e.Item as TreeListEditableItem;
    RequisitionListItem list = edataitem.DataItem as RequisitionListItem;
    string test23 = list.REQNum;

    Thanks for your help.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017