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

Access OwnerTableView ParentItem

2 Answers 152 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Faraz
Top achievements
Rank 1
Faraz asked on 10 Jan 2014, 06:50 AM
It is my Vb.net code it works perfectly.
Protected Sub ChkTaxCheckedChanged1(ByVal sender As Object, ByVal e As EventArgs)
  
     Dim chkTax As CheckBox
     Dim gv1 As GridDataItem
     chkTax = TryCast(sender, CheckBox)
     gv1 = DirectCast(chkTax.NamingContainer, GridDataItem)
  
     Dim txtAmount1 As Label
     txtAmount1= CType(gv1.OwnerTableView.ParentItem.FindControl("lblItemAmount"), Label)
  
End Sub


But now I want to achieve the same functionality in clientside using JavaScript. Like :
function ChkTaxCheckedChanged1(sender, args) {
  var check = sender.get_parent()..??????
}

How can I do this?

Please help me thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 10 Jan 2014, 08:25 AM
Hello,


<head runat="server">
    <title></title>
    <script src="Script/jquery-1.10.2.min.js"></script>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script>
            function handleClick(cb) {
                //i have used jquery so do not forgot add jquery reference
                var parentRow = $(cb).parent().parent().parent().parent().parent().parent()[0].previousSibling;
                $(parentRow).find('span').html('Your text comes here');
            }
        </script>
    </telerik:RadCodeBlock>
</head>
<body>
    <form id="form1" runat="server">
        <div>
 
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
            <telerik:RadWindowManager ID="RadWindowManager1" runat="server"></telerik:RadWindowManager>
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel>
            <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
                OnDetailTableDataBind="RadGrid1_DetailTableDataBind">
                <MasterTableView CommandItemDisplay="Top" DataKeyNames="ID">
                    <Columns>
                        <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name"></telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn>
                            <ItemTemplate>
                                <asp:Label ID="lblItemAmount" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                    <DetailTables>
                        <telerik:GridTableView>
                            <Columns>
                                <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name"></telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn>
                                    <ItemTemplate>
                                        <asp:CheckBox ID="ChkTax" runat="server" onclick='handleClick(this);' />
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                            </Columns>
                        </telerik:GridTableView>
                    </DetailTables>
                </MasterTableView>
            </telerik:RadGrid>
 
        </div>
    </form>
</body>
protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
{
    DataTable dt = new DataTable();
 
    dt.Columns.Add("ID", typeof(int));
    dt.Columns.Add("Name", typeof(string));
    dt.Columns.Add("Customdate", typeof(DateTime));
 
    dt.Rows.Add(11, "name11", DateTime.Now);
    dt.Rows.Add(22, "name22", DateTime.Now.AddYears(-1));
    dt.Rows.Add(33, "name33", DateTime.Now.AddYears(1));
 
    e.DetailTableView.DataSource = dt;
}
 
 
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable dt = new DataTable();
 
    dt.Columns.Add("ID", typeof(int));
    dt.Columns.Add("Name", typeof(string));
    dt.Columns.Add("Customdate", typeof(DateTime));
 
    dt.Rows.Add(1, "name1", DateTime.Now);
    dt.Rows.Add(2, "name2", DateTime.Now.AddYears(-1));
    dt.Rows.Add(3, "name3", DateTime.Now.AddYears(1));
 
    RadGrid1.DataSource = dt;
}

OR

http://www.telerik.com/community/code-library/aspnet-ajax/grid/accessing-and-validating-controls-client-side-inside-a-hierarchical-radgrid.aspx


Thanks,
Jayesh Goyani
0
Faraz
Top achievements
Rank 1
answered on 12 Jan 2014, 09:12 AM
Thank you 
Jayesh Goyani for help.
Tags
Grid
Asked by
Faraz
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Faraz
Top achievements
Rank 1
Share this question
or