get nestedview row from template control

4 posts, 0 answers
  1. Christian
    Christian avatar
    64 posts
    Member since:
    Apr 2008

    Posted 23 Oct 2013 Link to this post

    I have a case where i use a radbutton inside the nestedviewtemplate that uses 'OnClientCheckedChanged' event that i need to set the mastertable row´s expanded state and i cant seem to find out how to access the row dataitem from the button, does anyone have an idea?

    My nestedviewtemplate,

     

    <NestedViewTemplate>
              <asp:Panel ID="NestedViewPanel" runat="server" CssClass="divArtDetailsView">
                <div class="contactWrap">
                    <table width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                            <td width="140px">
                                <asp:Image runat="server" ID="imgArt" />
                            </td>
                            <td>
                                Diverse information ska in här, alla artikel extra kopplingar, fritext och lagerstatus
                            </td>
                            <td style="vertical-align:top; text-align:right; padding-right:5px;">
                                <telerik:RadButton runat="server" ID="btnPinRow" AutoPostBack="false" ButtonType="ToggleButton" ToggleType="CheckBox" Checked="false" OnClientCheckedChanged="pinChanged">
                                    <ToggleStates>
                                        <telerik:RadButtonToggleState Width="16px" IsBackgroundImage="true" ImageUrl="images/pinned.png"  />
                                        <telerik:RadButtonToggleState Width="16px" IsBackgroundImage="true" ImageUrl="images/unpinned.png" HoveredImageUrl="images/pinned.png" Selected="false" />
                                    </ToggleStates>
                                </telerik:RadButton>
                                <br /><br />
                                <telerik:RadNumericTextBox runat="server" ID="txtAnt" Width="45px" NumberFormat-DecimalDigits="0" Value="1"></telerik:RadNumericTextBox>
                                <telerik:RadButton runat="server" ID="btnAddToCart" Text="Add"></telerik:RadButton>
                            </td>
                        </tr>
                    </table>
                </div>
              </asp:Panel>
            </NestedViewTemplate>

     

     

    }
            function pinChanged(sender, eventArgs) {
     
                var button = sender;
                //how to find parent mastertable row dataitem??
            }

     

     

  2. Christian
    Christian avatar
    64 posts
    Member since:
    Apr 2008

    Posted 24 Oct 2013 Link to this post

    update,

    I found the rowIndex but its not the value I expected wich i think is caused by the fact it uses hierarchical grids but how do i figure out the itemindex för the mastertable?

    function pinChanged(sender, eventArgs) {
     
                var button = sender;
                var grid = $find("<%= grArtList.ClientID %>");
                var MasterTable = grid.get_masterTableView();
     
                var index = sender._element.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.rowIndex;
                 
                var dataitem = MasterTable.get_dataItems()[index];
                if (button.get_checked == true)
                {
                    dataitem.set_selected(true);
                }
                else
                {
                    dataitem.set_selected(false);
                }
            }
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 28 Oct 2013 Link to this post

    Hello Christian,

      In order to get the index of the row where the button was clicked you could use similar approach to the one you are using. Every row id in the RadGrid contains also the index. To get it you could use the split() function. Check the attached project for illustration of this approach.

    Note that if there are more hierarchy levels of the RadGrid the id's for the rows will be different.

    I hope this would be helpful to you.


    Regards,
    Viktor Tachev
    Telerik
    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 the blog feed now.
  5. Christian
    Christian avatar
    64 posts
    Member since:
    Apr 2008

    Posted 28 Oct 2013 Link to this post

    Thank you Viktor,

    I ended up going a different route by setting a html attribute on the control under itemdatabound of the grid. reason for this is as you mentioned that the rows index will change when applaing groupings and such and so i was stuck with this as my only solution but it worked out a treat.

    function pinChanged(sender, eventArgs) {
     
                var button = sender;
                var grid = $find("<%= grArtList.ClientID %>");
                var MasterTable = grid.get_masterTableView();
                var rowIndex = sender._element.getAttribute("rowindex");
     
                var dataitem = MasterTable.get_dataItems()[rowIndex];
     
                if (button.get_checked() == true)
                {
                    dataitem.set_selected(true);
                }
                else
                {
                    dataitem.set_selected(false);
                }
            }


    if (e.Item.ItemType == GridItemType.NestedView)
    {
       GridNestedViewItem nestedRow = (GridNestedViewItem)e.Item;
            

    GridDataItem row = (GridDataItem)nestedRow.ParentItem;


           RadButton btnPin = nestedRow.FindControl("btnPinRow") as RadButton;
       btnPin.Attributes.Add("rowindex", row.ItemIndex.ToString());
    }
Back to Top