Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > Grid > Accessing and validating controls client-side inside a hierarchical RadGrid

Answered Accessing and validating controls client-side inside a hierarchical RadGrid

Feed from this thread
  • Posted on Sep 30, 2011 (permalink)

    Requirements

    RadControls version 2011.1.519.40
    .NET version 4.0
    Visual Studio version 2010
    programming language C#
    browser support

    all browsers supported by RadControls


    PROJECT DESCRIPTION
    In this demo I am accessing the parent and child grid's rows on client-side.

    I have done below functionality on client-side.

    Part 1 : Get total of amount and total selected count.
    int totalAmount = 0;
                int totalSelected = 0;
                foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
                {
                    RadNumericTextBox RadNumericTextBox1 = item.FindControl("RadNumericTextBox1") as RadNumericTextBox;
                    if (!string.IsNullOrEmpty(RadNumericTextBox1.Text))
                    {
                        totalAmount += Convert.ToInt32(RadNumericTextBox1.Text);
                    }
                    if (item.HasChildItems)
                    {
                        foreach (GridDataItem citem in item.ChildItem.NestedTableViews[0].Items)
                        {
                            CheckBox CheckBox1 = citem.FindControl("CheckBox1") as CheckBox;
                            if (CheckBox1.Checked)
                            {
                                totalSelected++;
                            }
                        }
                    }
                }

    Part 2 : Doing validation on client side. (validation: if Amount is greater then zero then you must have to select any check box from child grid or vice versa)
    int totalAmount = 0;
                int totalSelected = 0;
                bool isGridhaveValidValue = true;
                foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
                {
                    RadNumericTextBox RadNumericTextBox1 = item.FindControl("RadNumericTextBox1") as RadNumericTextBox;
                    if (!string.IsNullOrEmpty(RadNumericTextBox1.Text))
                    {
                        totalAmount = Convert.ToInt32(RadNumericTextBox1.Text);
                    }
                    totalSelected = 0;
                    if (item.HasChildItems)
                    {
                        foreach (GridDataItem citem in item.ChildItem.NestedTableViews[0].Items)
                        {
                            CheckBox CheckBox1 = citem.FindControl("CheckBox1") as CheckBox;
                            if (CheckBox1.Checked)
                            {
                                totalSelected++;
                            }
                        }
                    }
     
                    if ((totalAmount == 0 && totalSelected > 0) || (totalAmount > 0 && totalSelected == 0))
                    {
                        isGridhaveValidValue = false;
                        break;
                    }
                }

    Note : In demo i used var childItems = childTable[0].get_dataItems();
    childTable[0] , I am accessing first detail table of grid
    childTable[1] , if you have more then one DetailTable at the same level, then you can access it like that. You can see demo Here.

    Let me know if any concern.

    Thanks,
    Jayesh Goyani
    Attached files

Back to Top

Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > Grid > Accessing and validating controls client-side inside a hierarchical RadGrid