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

Change DetailTable Column Based on another column

4 Answers 213 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Erik Willsey
Top achievements
Rank 1
Erik Willsey asked on 24 Sep 2009, 10:48 AM
I'm having trouble wrapping my head around how to implement something that I previously accomplished with a standard .Net DataGrid.  I've created a RadGrid control with a Master/Details table structure.  The detail columns include: ID, title, bReady, and bCompleted.  I want to programmatically check if bReady=false and if so set a hyperlink column to not be visible.  There are also some other pieces of logic I'd like to implement.

I tried using ItemDataBound of the Grid and OnDataBinding on the DetailsTable GridView, but nothing I've tried is working.

    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" DataSourceID="lpu" 
        GridLines="None" Width="576px"
        <MasterTableView DataKeyNames="uid" DataSourceID="lpu" HierarchyLoadMode="ServerBind"
            <DetailTables> 
                <telerik:GridTableView DataKeyNames="esi" 
                    DataSourceID="lps" Width="100%" runat="server" CommandItemDisplay="None"  
                    HeaderStyle-Height="0"
                    <ParentTableRelation> 
                        <telerik:GridRelationFields DetailKeyField="eui" MasterKeyField="eui" /> 
                    </ParentTableRelation> 
                    <Columns> 
                        <telerik:GridBoundColumn SortExpression="esi" HeaderText="esi" 
                            DataField="esi" UniqueName="esi" Visible="false" 
                            ReadOnly="true"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn AllowSorting="false" DataField="title" 
                            UniqueName="title"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn AllowSorting="false" DataField="bReady" Visible="true" 
                            UniqueName="bReady"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn AllowSorting="false" DataField="bCompleted" Visible="false" 
                            UniqueName="bCompleted"
                        </telerik:GridBoundColumn> 
                        <telerik:GridHyperLinkColumn DataNavigateUrlFormatString="javascript:launch('launch.aspx?esi={0}');" 
                            DataNavigateUrlFields="esi" DataType="Int32" Text="View"
                        </telerik:GridHyperLinkColumn> 
                    </Columns> 
 
<HeaderStyle Height="0px"></HeaderStyle> 
                </telerik:GridTableView> 
            </DetailTables> 
            <ExpandCollapseColumn Visible="True"
            </ExpandCollapseColumn> 
            <Columns> 
                <telerik:GridBoundColumn DataField="eui" DataType="System.Decimal" HeaderText="eui" 
                    ReadOnly="True" SortExpression="eui" UniqueName="eui" 
                    Visible="False"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="uo" DataType="System.Int32" HeaderText="uo" 
                    SortExpression="uo" UniqueName="uo" Visible="False"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="un" HeaderText="Name" SortExpression="un" 
                    UniqueName="un"
                </telerik:GridBoundColumn> 
            </Columns> 
        </MasterTableView> 
    </telerik:RadGrid> 
 

Can someone guide me on what I need to put into the ItemDataBound method to set up this behavior?  Here's where I've started but have gotten stuck.

Thanks

        if (e.Item is GridItem) 
        { 
            if (e.Item.OwnerTableView.ParentItem != null) 
            { 
                if (e.Item.OwnerTableView.DetailTables.Count > 0) 
                { 
                    foreach (GridTableView dt in e.Item.OwnerTableView.DetailTables ) { 
                        foreach (GridDataItem gdi in dt.Items) 
                        { 
                        } 
                    } 
                } 
            } 
        } 
 

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 24 Sep 2009, 11:29 AM
Hello Erik Willsey,

You can try out the following code to hide the hyperlink based on a condition:
aspx:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" DataSourceID="lpu"   
        GridLines="None" Width="576px">   
    <MasterTableView DataKeyNames="uid"  DataSourceID="lpu" HierarchyLoadMode="ServerBind">   
         <DetailTables>   
              <telerik:GridTableView DataKeyNames="esi" Name="Detail"  DataSourceID="lps" Width="100%" runat="server" CommandItemDisplay="None"    
                    HeaderStyle-Height="0">   
                        ....  
                 <Columns>   
                        ....  
                    <telerik:GridBoundColumn AllowSorting="false" DataField="bReady" Visible="true"   
                            UniqueName="bReady">   
                    </telerik:GridBoundColumn>   
                        ....  
                    <telerik:GridHyperLinkColumn UniqueName="HyperlinkColumnUniqueName" DataNavigateUrlFormatString="javascript:launch('launch.aspx?esi={0}');" DataNavigateUrlFields="esi" DataType="Int32" Text="View">   
                     </telerik:GridHyperLinkColumn>   
                 </Columns>   

c#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Detail"
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            if (item["bReady"].Text == "false"
            { 
                ((HyperLink)item["HyperlinkColumnUniqueName"].Controls[0]).Visible = false
            } 
        } 
    } 

Thanks
Princy.
0
Erik Willsey
Top achievements
Rank 1
answered on 24 Sep 2009, 11:43 AM
Thanks for your quick response.  I couldn't get it working though. I even tried commenting out the conditional portion.  The link field still displays visible all the time. Here's my new code based on your response:

    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" DataSourceID="lpu" 
        GridLines="None" Width="576px" OnItemDataBound="RadGrid_ItemDataBound">  
        <MasterTableView DataKeyNames="eui" DataSourceID="lpu" HierarchyLoadMode="ServerBind">  
            <DetailTables> 
                <telerik:GridTableView DataKeyNames="esi" 
                    DataSourceID="lps" Width="100%" runat="server" CommandItemDisplay="None"   
                    HeaderStyle-Height="0">  
                    <ParentTableRelation> 
                        <telerik:GridRelationFields DetailKeyField="eui" MasterKeyField="eui" /> 
                    </ParentTableRelation> 
                    <Columns> 
                        <telerik:GridBoundColumn SortExpression="esi" HeaderText="esi" 
                            DataField="esi" UniqueName="esi" Visible="false" 
                            ReadOnly="true">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn AllowSorting="false" DataField="title" 
                            UniqueName="title">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn AllowSorting="false" DataField="bReadyToView" Visible="true" 
                            UniqueName="bReadyToView">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn AllowSorting="false" DataField="bCompleted" Visible="false" 
                            UniqueName="bCompleted">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridHyperLinkColumn DataNavigateUrlFormatString="javascript:launch('launch.aspx?esi={0}');" 
                            DataNavigateUrlFields="esi" DataType="Int32" Text="View" UniqueName="View">  
                        </telerik:GridHyperLinkColumn> 
                    </Columns> 
 
<HeaderStyle Height="0px"></HeaderStyle> 
                </telerik:GridTableView> 
            </DetailTables> 
            <ExpandCollapseColumn Visible="True">  
            </ExpandCollapseColumn> 
 

 

    protected void RadGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)    
    {  
        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Detail")  
        {  
            GridDataItem item = (GridDataItem)e.Item;  
            //if (item["bReady"].Text == "0")  
            //{  
                ((HyperLink)item["View"].Controls[0]).Visible = false;  
            //}  
        }  
    }  
 

Thanks,
Erik
0
Princy
Top achievements
Rank 2
answered on 24 Sep 2009, 12:17 PM
Hi Erik,

Did you try setting the Name property for the DetailTableView i.e., 'Name="Detail" ' in the aspx?

-Princy.
0
Erik Willsey
Top achievements
Rank 1
answered on 24 Sep 2009, 12:24 PM
DOH, I overlooked that property change in your reply.  After setting it, everything worked.  Much thanks!
Tags
Grid
Asked by
Erik Willsey
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Erik Willsey
Top achievements
Rank 1
Share this question
or