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

Nested Grid issues

1 Answer 26 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris Hoare
Top achievements
Rank 1
Chris Hoare asked on 14 Nov 2012, 04:59 PM

The following code is used to render a Grid with a nested grid, all Data is bound using NeedDataSource
The issues are as follows
1) there is no expand icon displayed
2) Master grid is reset when the child grid is displayed, the columns that were set using code behind are reset

So What I need is the following, The Delete row Icon is displayed only if the data has a Status of 'A'
If no delete icon is displayed the we will show a icon for Sucess or Failed or Processing

if the Status is Failed, then we should be able to expand the grid to see the errors listed, again if any other status then no expand to be displayed.

There are no internal styles to be used.

Mark up Code

<telerik:RadGrid
runat="server"
ID="RadGrid2"
EnableEmbeddedSkins="False"
ShowStatusBar="True"
AllowPaging="True"
AutoGenerateColumns="False"
CellSpacing="0"
width="795px" GridLines="None" >
<ActiveItemStyle CssClass="alternate" />
<MasterTableView >
<ExpandCollapseColumn
Visible="True"
CollapseImageUrl="~/Images/collapse-large-silver.png"
ExpandImageUrl="~/Images/expand-large-silver.png"
/>
<Columns>
<telerik:GridBoundColumn DataField="ImportHeaderID" Display="False" UniqueName="ImportHeaderID" Visible="False" />
<telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" HeaderStyle-Width="40px" ImageUrl="~/Images/icon-quick-link-delete.png" Text="Delete" UniqueName="DeleteColumn">
<HeaderStyle Width="40px" />
</telerik:GridButtonColumn>
<telerik:GridHyperLinkColumn AllowFiltering="False" DataNavigateUrlFields="ImportHeaderID" DataNavigateUrlFormatString="~/DisplayFile.aspx?HeaderID={0}" DataTextField="ImportHeaderFilename" HeaderStyle-Width="200px" HeaderText="Filename" Target="_blank" UniqueName="Filename">
<HeaderStyle Width="200px" />
</telerik:GridHyperLinkColumn>
<telerik:GridDateTimeColumn AllowFiltering="False" DataField="importHeaderFileLoadDate" HeaderStyle-Width="200px" HeaderText="Uploaded" ReadOnly="true" UniqueName="Uploaded">
<HeaderStyle Width="200px" />
</telerik:GridDateTimeColumn>
<telerik:GridBoundColumn AllowFiltering="False" DataField="importHeaderCreatedBy" HeaderStyle-Width="200px" HeaderText="CreatedBy" ReadOnly="true" UniqueName="CreatedBy">
<HeaderStyle Width="200px" />
</telerik:GridBoundColumn>
</Columns>
<NestedViewTemplate>
<asp:Panel ID="Errors" runat="server">
<telerik:RadGrid ID="ErrorGrid"
runat="server"
EnableEmbeddedSkins="False"
ShowStatusBar="True"
AllowPaging="True"
AutoGenerateColumns="False"
CellSpacing="0"
ShowHeader="False">
<MasterTableView Name="inner">
<Columns>
<telerik:GridBoundColumn DataField="ErrorDescription" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
</asp:Panel>
</NestedViewTemplate>
<NoRecordsTemplate>
<div>Please select filter Settings from above</div>
</NoRecordsTemplate>
</MasterTableView>
<HeaderContextMenu EnableEmbeddedSkins="False"></HeaderContextMenu>
</telerik:RadGrid>

Code behind

Protected Sub RadGrid2_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs) Handles RadGrid2.NeedDataSource
Dim ds As DataSet = DAL.DAL.SelectImportedFiles(0)
RadGrid2.DataSource = ds
End Sub
Protected Sub RadGrid2_ItemCreated(sender As Object, e As GridItemEventArgs) Handles RadGrid2.ItemCreated
If TypeOf e.Item Is GridNestedViewItem Then
AddHandler TryCast(e.Item.FindControl("ErrorGrid"), RadGrid).NeedDataSource, AddressOf Me.ErrorGrid_NeedDataSource
End If
End Sub
Protected Sub ErrorGrid_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)
Dim nestedItem As GridNestedViewItem = DirectCast(TryCast(sender, RadGrid).NamingContainer, GridNestedViewItem)
Dim dataKeyValue As String = nestedItem.ParentItem.Item("ImportHeaderID").Text
If IsNumeric(dataKeyValue) Then
Dim ds As DataSet = DAL.DAL.SelectImportedErrors(CInt(dataKeyValue))
CType(sender, RadGrid).DataSource = ds
End If
End Sub
Private Sub RadGrid2_ItemCommand(source As Object, e As GridCommandEventArgs) Handles RadGrid2.ItemCommand
If e.CommandName = RadGrid.ExpandCollapseCommandName Then
Dim item As GridDataItem = TryCast(e.Item, GridDataItem)
If Not item.Expanded Then
Dim nestedItem As GridNestedViewItem = DirectCast(item.ChildItem, GridNestedViewItem)
Dim tempGrid As RadGrid = DirectCast(nestedItem.FindControl("ErrorGrid"), RadGrid)
tempGrid.Rebind()
End If
End If
End Sub
Protected Sub RadGrid2_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles RadGrid2.ItemDataBound
If e.Item.ItemType = GridItemType.AlternatingItem Or e.Item.ItemType = GridItemType.Item Then
Dim ds As DataSet = TryCast(RadGrid2.DataSource, DataSet)
If ds.Tables(0).Rows(DirectCast(e.Item, Telerik.Web.UI.GridDataItem).DataSetIndex)("ImportHeaderState") <> "A" Then
Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
Dim cellDelete As TableCell = item("DeleteColumn")
cellDelete.Controls.Clear()
Dim img As New Image
Select Case ds.Tables(0).Rows(DirectCast(e.Item, Telerik.Web.UI.GridDataItem).DataSetIndex)("ImportHeaderState")
Case "P"
img.ImageUrl = "~/images/icon-notification-box.gif"
Case "S"
img.ImageUrl = "~/images/icon-notice-box.png"
Case "F"
img.ImageUrl = "~/images/icon_status_fail_26x26.gif"
End Select
cellDelete.Controls.Add(img)
End If
If ds.Tables(0).Rows(DirectCast(e.Item, Telerik.Web.UI.GridDataItem).DataSetIndex)("ImportHeaderState") <> "F" Then
Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
Dim cellExpand As TableCell = item("ExpandColumn")
cellExpand.Controls.Clear()
End If
End If
End Sub

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 19 Nov 2012, 01:36 PM
Hi Chris,

Thank you for contacting us.

I have created a sample RadGrid web site using the provided code snippets where I implemented the requested functionality. Please check out the attached application and let me know about the result.

Kind regards,
Eyup
the Telerik team
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 their blog feed now.
Tags
Grid
Asked by
Chris Hoare
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or