Child Controls in Rad Grid

4 posts, 0 answers
  1. Velkumar
    Velkumar avatar
    85 posts
    Member since:
    Apr 2011

    Posted 08 Apr 2011 Link to this post

    I have a RadGrid with checkbox( GridClientSelectColumn ) to select a row. All  columns are created using templates. How can i get the child controls in  the RadGrid from client side using javascript and from server side using C#.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Apr 2011 Link to this post

    Hello Velkumar,

    I guess you want to access the control inside ItemTemplate of selected rows. If so try the following code snippet.

    ASPX:
    <telerik:GridTemplateColumn>
        <ItemTemplate>
           <asp:Label ID="Label1" runat="server" ></asp:Label>
        </ItemTemplate>
    </telerik:GridTemplateColumn>

    C#:
    protected void Button1_Click(object sender, EventArgs e)
       {
           GridDataItem item = (GridDataItem)RadGrid1.SelectedItems[0];
           Label lb = (Label)item.FindControl("Label1");//accessing Label control
       }


    Java Script:
    <script type="text/javascript">
         function ButtonClick()
          {
            var grid = $find("<%=RadGrid1.ClientID %>");
            var MasterTable = grid.get_masterTableView();
            for (var i = 0; i < MasterTable.get_selectedItems().length; i++) {
                var cellValue1 = MasterTable.get_selectedItems()[i].findElement("Label1").innerHTML;
           }
        }
    </script>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Velkumar
    Velkumar avatar
    85 posts
    Member since:
    Apr 2011

    Posted 09 Apr 2011 Link to this post

    Hello Princy ,

                I am using the following code to create Checkbox in the first column of each row in RadGrid.

                      GridClientSelectColumn tmpColumn1 = new GridClientSelectColumn();
                      RadGridTaxRate.MasterTableView.Columns.Add(tmpColumn1);


    Using this code we can create checkbox in each row. My goal is to get the object of this checkbox in row select event.





    Thanks,
    Velkumar.

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

    Posted 11 Apr 2011 Link to this post

    Hello VelKumar,

    Give a try with the following approach to access the CheckBox in GridClientSelectColumn from client side.

    ASPX:
    <telerik:RadGrid ID="RadGrid1"  runat="server" OnItemCreated="RadGrid1_ItemCreated">
         .   .   .   .   .  .   /
        <ClientSettings Selecting-AllowRowSelect="true">
            <ClientEvents OnRowSelecting="RowSelecting" />
        </ClientSettings>
    </telerik:RadGrid>
     
    <asp:HiddenField ID="HiddenField1" runat="server" />

    C#:
    GridClientSelectColumn tmpColumn1 = new GridClientSelectColumn();
    tmpColumn1.UniqueName = "GridClientSelectColumn";
    RadGridTaxRate.MasterTableView.Columns.Add(tmpColumn1);

    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
     {
         if (e.Item is GridDataItem)
         {
             GridDataItem item = (GridDataItem)e.Item;
             CheckBox chk = (CheckBox)item["GridClientSelectColumn"].Controls[0];
             HiddenField1.Value = chk.ClientID;
         }
     }

    Java script:
    <script type="text/javascript">
        function RowSelecting(sender, args) {
            var grid = sender;
            var masterTable = sender.get_masterTableView();
            var Checkbox = document.getElementById(document.getElementById('HiddenField1').value); //accessing CheckBox usig HiddenField value
          }
    </script>

    Thanks,
    Princy.
Back to Top