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

get nestedview row from template control

3 Answers 134 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 23 Oct 2013, 11:04 AM

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??
        }

 

 

3 Answers, 1 is accepted

Sort by
0
Christian
Top achievements
Rank 1
answered on 24 Oct 2013, 06:19 AM

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);
            }
        }
0
Viktor Tachev
Telerik team
answered on 28 Oct 2013, 11:31 AM
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.
0
Christian
Top achievements
Rank 1
answered on 28 Oct 2013, 11:56 AM
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());
}
Tags
Grid
Asked by
Christian
Top achievements
Rank 1
Answers by
Christian
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or