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

making rad grid Inidividual cell read only based ona condition.

2 Answers 186 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Venkatesh
Top achievements
Rank 1
Venkatesh asked on 14 Aug 2014, 12:18 PM
Hi,



I want to make read only for the rad grid cells based on a condition.

 

Eg:  1      2     3      N/A    5        6      7     N/A

        23   34   56    12      N/A    12     10   33



The cells which is having N/A i need to make read only.



I am using radgrid batch edit with GridTemplateColumn. Label in ItemTemplate, RadNumericTextBox  in EditItemTemplate.





Regards,

Venkatesh.

2 Answers, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 18 Aug 2014, 10:22 AM
Hello Venkatesh,

For achieving such behavior, which simulates a read only cell when some condition is met, you should handle the client-side OnBatchEditOpenening event of the grid, retrieve the current cell value through the Batch Editing Manager getCellValue(cell) method and cancel the event (if the value is "N/A" for your scenario).

For your convenience, following is a simple example demonstrating the above approach. Please give it a try and see if it meets you exact requirement:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function batchEditOpening(sender, args) {
            var batchManager = sender.get_batchEditingManager();
            var cellValue = batchManager.getCellValue(args.get_cell());
            if (cellValue == "N/A") {
                args.set_cancel(true);
            }
        }
    </script>
</telerik:RadCodeBlock>
 
 
<telerik:RadGrid ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound"     
    runat="server">
    <MasterTableView AutoGenerateColumns="false" EditMode="Batch">
        <Columns>
            <telerik:GridTemplateColumn UniqueName="Value1">
                <ItemTemplate>
                    <asp:Label Text='<%#Eval("Value1") %>' runat="server" />
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadNumericTextBox runat="server"></telerik:RadNumericTextBox>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>                  
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnBatchEditOpening="batchEditOpening" />
    </ClientSettings>
</telerik:RadGrid>

And the dummy data:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Value1", typeof(Decimal));
    for (int i = 0; i < 10; i++)
    {
        table.Rows.Add(i, i);
        table.Rows.Add(i);
    }
 
    (sender as RadGrid).DataSource = table;
 
}
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
        if (string.IsNullOrEmpty((item["Value1"].Controls[1] as Label).Text))
        {
            item["Value1"].Text = "N/A";
        }
    }
}

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Venkatesh
Top achievements
Rank 1
answered on 18 Aug 2014, 01:46 PM
Hi Konstantin,

Thank you very much for the solution. Its working properly like what i need.

Regards,
Venkatesh.
Tags
General Discussions
Asked by
Venkatesh
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Venkatesh
Top achievements
Rank 1
Share this question
or