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

Get TreeList Column Value - ItemCreated

5 Answers 278 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 08 Mar 2012, 08:51 PM
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 + ");";
           }
       }


5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Mar 2012, 08:14 AM
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.
0
William
Top achievements
Rank 1
answered on 09 Mar 2012, 02:49 PM
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.
0
Maria Ilieva
Telerik team
answered on 14 Mar 2012, 02:11 PM
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.
0
William
Top achievements
Rank 1
answered on 14 Mar 2012, 03:11 PM
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. 
0
William
Top achievements
Rank 1
answered on 14 Mar 2012, 03:19 PM
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.
Tags
TreeList
Asked by
William
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
William
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or