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

How to access GridNumericColumn in ItemDatabind

1 Answer 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Suzy
Top achievements
Rank 2
Suzy asked on 05 Jan 2016, 10:08 AM

Hi

 I have a GridNumericColumn in my RadGrid (with automatic updates).  Depending on the data loaded the GridNumericColumn may or may not be editable.

How can I set the ReadOnly of the GridNumericColumn in ItemDataBind?

<telerik:GridNumericColumn HeaderText="Quarter1" HeaderStyle-Width="5%" ItemStyle-Width="5%" HeaderButtonType="TextButton" DataField="quarter1" UniqueName="quarter1" AllowFiltering="false" DecimalDigits="0" MinValue="0" MaxValue="999999999" ></telerik:GridNumericColumn>
                    

protected void grdForecasts_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                GridDataItem item = e.Item as GridDataItem;
                if (item != null)
                {
                    DataRowView dataItem = ((DataRowView)item.DataItem);
                    TableCell Quarter1 = item["quarter1"];
                    switch (DateTime.Now.Month)
                    {
                        case 4:
                        case 5:
                        case 6:
                            Quarter1.ReadOnly = true; // This is not working
                            break;
                    }
                                     
                }
          }
    }

Kind regards

 Suzy

 

 

 

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 08 Jan 2016, 06:49 AM
Hello Suzy,

You can use the cell and find the RadNumericTextBox inside. Note that you would need to ensure that the item is in edit mode. When the row is not being edited the RadNumericTextBox will not be rendered.

If you would like additional information on how you can access controls in the cells or rows of RadGrid you would find the following article interesting.


The ItemDataBound event would look similar to the following:


protected void grdForecasts_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridDataItem item = e.Item as GridDataItem;
 
        if (item != null)
        {
            DataRowView dataItem = ((DataRowView)item.DataItem);
 
            TableCell cell = item["quarter1"];
 
            RadNumericTextBox numericBox = cell.Controls[0] as RadNumericTextBox;
 
        }
    }
}


Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Suzy
Top achievements
Rank 2
Answers by
Viktor Tachev
Telerik team
Share this question
or