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

Cell visibility based on another cell value

3 Answers 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 2
Mike asked on 04 Nov 2014, 04:27 PM
Hi,

In it's simplest form I have a RadGrid containing a Milestone indicator column, a Title and a Value.
If the particular row is a Milestone, then this should not have an associated value.

I am unsure how to get a reference to whether the current row is a 'Milestone' row and, if so, simply hide the label that is generated for the 'External Costs' column.

My grid is structured as follows (simplified): -

<telerik:RadGrid ID="costingGrid" runat="server" RenderMode="Auto" OnNeedDataSource="costingGrid_NeedDataSource" AllowAutomaticUpdates="true" ClientSettings-AllowKeyboardNavigation="true">
<ClientSettings>
            <Selecting AllowRowSelect="true" />
            <ClientEvents OnRowCreated="gridRowCreated" />
            <Scrolling AllowScroll="true" UseStaticHeaders="true" />
        </ClientSettings>
<MasterTableView AutoGenerateColumns="false" DataKeyNames="ID" Width="100%" EditMode="Batch" CommandItemDisplay="Top" ShowFooter="true">
<BatchEditingSettings EditType="Cell" OpenEditingEvent="Click" />
<Columns>
<telerik:GridBoundColumn UniqueName="ID" DataField="ID" Visible="false" />
                <telerik:GridBoundColumn UniqueName="IsMilestone" DataField="IsMilestone" Display="false" />
<telerik:GridTemplateColumn UniqueName="Title" DataField="Title" HeaderText="Title" HeaderStyle-Width="400px" >
                    <ItemTemplate>
                        <asp:Label ID="titleLabel" runat="server" Width="100%" Text='<%#Bind("Title") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadTextBox ID="titleInput" runat="server" Width="100%" TextMode="MultiLine" />
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
<telerik:GridBoundColumn UniqueName="ExternalCosts" DataField="ExternalCosts" HeaderText="3rd Party Costs" HeaderStyle-Width="80px"  DataFormatString="{0:N2}" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" Aggregate="Sum" FooterAggregateFormatString="£{0:F2}" />
</MasterTableView>
    </telerik:RadGrid>

<telerik:RadScriptBlock runat="server">
        <script type="text/javascript">
             
            function gridRowCreated(sender, args) {
 
            }
        </script>
    </telerik:RadScriptBlock>
protected void costingGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            costingGrid.DataSource = CurrentCosting.Lines.OrderBy(l => l.LineNumber).ToList();
        }

Many thanks,
Mike.

3 Answers, 1 is accepted

Sort by
0
Accepted
Jay
Top achievements
Rank 1
Iron
Veteran
answered on 04 Nov 2014, 05:47 PM
I think you could do it with ItemDataBound, adding

OnItemDataBound="costingGrid_ItemDataBound"

to your RadGrid attributes, and in the code behind,

protected void costingGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem) e.Item;
        if (bool.Parse(item["IsMilestone"].Text))
        {
            item["ExternalCosts"].Text = "";
        }
    }
}
 
Not sure about doing it on the client side, maybe something like

function gridRowCreated(sender, args) {       
        var rowIndex = eventArgs.get_gridDataItem().get_element().rowIndex;
        var grid = sender;
        var MasterTable = grid.get_masterTableView();
        var row = MasterTable.get_dataItems()[rowIndex];
        var mscell = MasterTable.getCellByColumnUniqueName(row, "IsMilestone");
        if (mscell.innerHTML == "true" /* or something */) {
            var eccell = MasterTable.getCellByColumnUniqueName(row, "ExternalCosts");
            eccell.innerHTML = "";
        }
}

0
Mike
Top achievements
Rank 2
answered on 04 Nov 2014, 07:22 PM
That's great, thanks Jay.
0
Jay
Top achievements
Rank 1
Iron
Veteran
answered on 04 Nov 2014, 07:50 PM
You're welcome. Like I said, there might be a better way to do it on the client, rather than going through the MasterTable, since you've already got the grid data item on the event args.
Tags
Grid
Asked by
Mike
Top achievements
Rank 2
Answers by
Jay
Top achievements
Rank 1
Iron
Veteran
Mike
Top achievements
Rank 2
Share this question
or