Hi
For long time I've been trying to achieve simple functionality: nest one rad grid into another, to get something similar to PanelBar. I simply want to be able to click on a row, which would then expand and show inner rad grid. This I've managed to do. However, I'm having really big problem with using this mechanism since all commands from nested grid are transferred automatically to master grid. This way I cannot select nested grid's row because each click collapses my master row.
I've tried already setting inner grid's ItemCommand event,but with no success, still incorrect (in my opinion) behavior occurs.
Below I'm posting snippet with aspx and some code to manage those grid. Could you help me resolving this issue? How can I be able to select row from nested grid? Or process any item command for nested grid?
<telerik:RadGrid ID="gridNodes" runat="server" AutoGenerateColumns="false" ShowHeader="false" GridLines="None"> <ClientSettings EnablePostBackOnRowClick="true"EnableRowHoverStyle="true" /> <MasterTableView GroupLoadMode="Server" DataKeyNames="NodeId" AutoGenerateColumns="false" Name="master"> <NestedViewTemplate> <asp:Panel ID="pnlStatements" runat="server"> <telerik:RadGrid ID="gridStatements" runat="server" AutoGenerateColumns="false" ShowHeader="false"> <MasterTableView Name="inner"> <Columns> <telerik:GridNumericColumn DataField="Id" Visible="false" /> <telerik:GridBoundColumn DataField="Value" /> </Columns> </MasterTableView> </telerik:RadGrid> </asp:Panel> </NestedViewTemplate> <Columns> <telerik:GridBoundColumn UniqueName="NodeName" HeaderText="Node name" DataField="NodeName" /> </Columns> </MasterTableView> </telerik:RadGrid>
Protected Sub gridNodes_NeedDataSource(ByVal sender As Object, ByVal e As GridNeedDataSourceEventArgs) _ Handles gridNodes.NeedDataSource Me.gridNodes.DataSource = Me.ConsumptionContextViewModel.GetNodeWithParents() End SubProtected Sub gridNodes_DataBound(ByVal sender As Object, ByVal e As EventArgs) _ Handles gridNodes.DataBound If (gridNodes.Items.Count > 0) Then gridNodes.Items(0).Expanded = True End IfEnd SubProtected Sub gridNode_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) _ Handles gridNodes.ItemCreated If (TypeOf (e.Item) Is GridNestedViewItem) Then Dim typeContent = DirectCast(e.Item.FindControl("gridStatements"), RadGrid) AddHandler typeContent.NeedDataSource, AddressOf Me.gridStatements_NeedDataSource AddHandler typeContent.ItemCommand, AddressOf Me.gridStatements_ItemCommand End IfEnd SubProtected Sub gridStatements_NeedDataSource(ByVal sender As Object, ByVal e As GridNeedDataSourceEventArgs) Dim grid = DirectCast(sender, RadGrid) Dim nodeId = DirectCast(grid.NamingContainer, GridNestedViewItem).ParentItem.GetDataKeyValue("NodeId") grid.DataSource = Me.ConsumptionContextViewModel.GetTextsForNode(CInt(nodeId)) End SubProtected Sub gridNode_ItemCommand(ByVal sender As Object, ByVal e As GridCommandEventArgs) _ Handles gridNodes.ItemCommand Select Case e.CommandName Case RadGrid.ExpandCollapseCommandName If (Not TypeOf (e.Item) Is GridDataItem) Then Return End If ' close all items except current. e.Item.Expanded will be expanded after leaving ItemCommand method For Each item As GridItem In gridNodes.MasterTableView.Items If item.Expanded AndAlso item IsNot e.Item Then item.Expanded = False End If Next ' select expanded row e.Item.FireCommandEvent(RadGrid.SelectCommandName, e) ' explicitly rebind inner container If (e.Item.Expanded = False) Then Dim dataItem = DirectCast(e.Item, GridDataItem) Dim innerContainer = DirectCast(dataItem.ChildItem.FindControl("gridStatements"), RadGrid) innerContainer.Rebind() End If Case "RowClick" ' manually fire expand event e.Item.FireCommandEvent(RadGrid.ExpandCollapseCommandName, New GridExpandCommandEventArgs(e.Item, sender, e)) Case Else ' do nothing End SelectEnd SubRegards,
Pako
this.Grid.ExportSettings.ExportOnlyData = true;this.Grid.ExportSettings.OpenInNewWindow = true;this.Grid.MasterTableView.ExportToExcel();
| <script type="text/javascript"> function ShowDescriptionForm() { window.radopen("test.aspx", "ShowComment"); return false; } </script> <div align="center"> |
| <object style="height: 245px; width: 301px;"> |
| <param name="movie" value="http://www.youtube.com/v/cL9Wu2kWwSY&color1=0xb1b1b1&color2=0xcfcfcf&feature=player_embedded&fs=1"> |
| </param> |
| <param name="allowFullScreen" value="true"></param> |
| <param name="allowScriptAccess" value="always"></param> |
| <embed src="http://www.youtube.com/v/cL9Wu2kWwSY&color1=0xb1b1b1&color2=0xcfcfcf&feature=player_embedded&fs=1" |
| type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" |
| width="301" height="245"></embed></object> |
| <br /> |
| <br /> |
| <br /> |
| <p> |
| <asp:LinkButton runat="server" ID="lbtnTest" Text="Test" OnClientClick="return ShowDescriptionForm();"></asp:LinkButton> |
| </p> |
| <telerik:RadWindowManager ID="RadWindowManager1" runat="server" > |
| <Windows> |
| <telerik:RadWindow ID="ShowComment" runat="server" Width="600px" Style="z-index: 10000" |
| Height="650px" Modal="true" ShowContentDuringLoad="false" VisibleStatusbar="false" /> |
| </Windows> |
| </telerik:RadWindowManager> |
| </div> |
function gridCommand(sender, args) { if (args.get_commandName() == "DownloadAttachment") { // some logic here } }