Get cell value on ColumnButton click

7 posts, 0 answers
  1. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 27 Dec 2014 Link to this post

    I am just starting with the TreeList.
    I have a button column and several boundColumns.
    How do I get the value of a column on button click in the same row?

    thanks
    Felice
  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1798 posts

    Posted 29 Dec 2014 Link to this post

    Hello Felice,

    In order to retrieve a specific data field value from an item you should first include that data field in the ClientDataKeyNames collection of the RadTreeList if your requirement is to retrieve the value on client-side. Using the button element you can then get reference to the corresponding TR element of the item and using the id of the TR element, to find the data item. Once you have reference to the data item you can use the get_dataKeyValue() method for retrieving the value:
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function buttonClick(sender, args) {
                var buttonElement = sender.get_element();
                var treeList = $find("<%=RadTreeList2.ClientID%>");
                var itemElement = treeList._getFirstParentByTagName(buttonElement, "TR");
                treeList.get_dataItems();
                var dataItem = $find(itemElement.id);
                var employeeID = dataItem.get_dataKeyValue("EmployeeID");
            }
        </script>
    </telerik:RadCodeBlock>
     
    <telerik:RadAjaxPanel ID="RadAjaxPanel2" LoadingPanelID="RadAjaxLoadingPanel1" runat="server">
        <telerik:RadTreeList runat="server" ID="RadTreeList2" AllowPaging="true" PageSize="3" ClientDataKeyNames="EmployeeID" DataKeyNames="EmployeeID"
            ParentDataKeyNames="ReportsTo" OnNeedDataSource="RadTreeList2_NeedDataSource">
            <Columns>
                <telerik:TreeListTemplateColumn>
                    <ItemTemplate>
                        <telerik:RadButton runat="server" ID="RadButton1" AutoPostBack="false" Text="Test click" OnClientClicked="buttonClick"></telerik:RadButton>
                    </ItemTemplate>
                </telerik:TreeListTemplateColumn>
            </Columns>
        </telerik:RadTreeList>
    </telerik:RadAjaxPanel>

    And the code-behind:
    public DataTable GetDataTable()
    {
        String ConnString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
        SqlConnection conn = new SqlConnection(ConnString);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand("SELECT EmployeeID, LastName, FirstName, Title, TitleOfCourtesy, ReportsTo FROM Employees", conn);
        DataTable myDataTable = new DataTable();
        conn.Open();
        try
        {
            adapter.Fill(myDataTable);
        }
        finally
        {
            conn.Close();
        }
        return myDataTable;
    }
     
    protected void RadTreeList2_NeedDataSource(object source, TreeListNeedDataSourceEventArgs e)
    {
        RadTreeList2.DataSource = GetDataTable();
    }

    The same principal should be used with a server-side requirement, where you can handle the OnItemCommand event of the RadTreeList and use the GetDataKeyValue method of the TreeListDataItem:
    protected void RadTreeList2_ItemCommand(object sender, TreeListCommandEventArgs e)
    {
        if (e.CommandName == "customCommandName")
        {
            if (e.Item is TreeListDataItem)
            {
                TreeListDataItem item = e.Item as TreeListDataItem;
                string id = item.GetDataKeyValue("EmployeeID").ToString();
            }
        }      
    }

    Hope this helps.


    Regards,
    Konstantin Dikov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 29 Dec 2014 in reply to Konstantin Dikov Link to this post

    Hello Konstantin,
    thanks a lot for the snippet. Looks like I have a little problem here.....the property panel of the radTreeList is completely empty as you can see from the attached pic.
    I also tried to delete the control and make a new one but still the same.
    How can I get to the events of the treeList? Should I write them in the xml file? Is this a bug?

    Thanks,
    Felice
  5. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1798 posts

    Posted 01 Jan 2015 Link to this post

    Hello Felice,

    Can you please share what version of the controls you are using, so we can test the same version on our end.

    As for attaching the event handler, you should use either the markup of your page or the code-behind:
    protected void Page_Load(object sender, EventArgs e)
    {
        RadTreeList1.NeedDataSource += RadTreeList1_NeedDataSource;
    }
     
    void RadTreeList1_NeedDataSource(object sender, TreeListNeedDataSourceEventArgs e)
    {
        //
    }

    On a side note, please take a look at the following help articles, that should help you in the beginning:

    Best Regards,
    Konstantin Dikov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 01 Jan 2015 in reply to Konstantin Dikov Link to this post

    Hi Konstantin,
    I am using Q3 2014.
    Thanks,
    Felice
  7. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 01 Jan 2015 in reply to Konstantin Dikov Link to this post

    I am using Q3 2014

    Thanks
  8. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1798 posts

    Posted 05 Jan 2015 Link to this post

    Hello Felice,

    I have tested the RadTreeList control in a simple project and the Properties window is displaying all the properties as expected.

    Can you please test with other controls and see if their properties will be visible in the Properties window. Also, please try to create a new project and see if the same issue will be observed.

    I am looking forward to your reply with the results.


    Regards,
    Konstantin Dikov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

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