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

EditForm - how to set column to read-only

7 Answers 215 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Minh
Top achievements
Rank 1
Minh asked on 03 Aug 2011, 08:12 PM
Hi,

during the edit of a row within the grid, I would like to set a column to read-only based on the drop-down selection of a previous column.
for example:

column A - drop down selection is Read ----------->set column B to read-only (or grey it out)
column A - drop down selection is Write ----------->set column B to allow input

I'm using the built-in grid editform

I'm using ASP.NET version 4 with the 2011.1 519 (May 19, 2011)  radcontrol
programming language is c#
Internet explorer 

also...any information on extending the grid built-in editform features, api, coding would be helpful.

thanks,
Minh 

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Aug 2011, 05:03 AM
Hello MInh,

You can achieve this in two ways.
If you want to set the column in ReadOnly based on the SelectedValue of DropDownList, then you can access the BoundColumn in SelectedIndexChanged event of the DropDownList as shown below.
C#:
protected void drop_SelectedIndexChanged1(object sender, EventArgs e)
{
        DropDownList list = sender as DropDownList;
        GridEditableItem item = (GridEditableItem)list.NamingContainer;
        TextBox txt = (TextBox)item["ColumnUniqueName"].Controls[0];
        txt.ReadOnly = true;
}

Another method is you can attach ItemDataBound event and set ReadOnly property as shown below.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted)        
{
     GridEditableItem edititem = (GridEditableItem)e.Item;
     TextBox txt= edititem["ColumnUniqueName"].Controls[0] as TextBox;
     txt.ReadOnly = true;
}
}

Thanks,
Princy.
0
Pierre
Top achievements
Rank 1
answered on 04 Aug 2011, 10:36 PM
Well Princy I've tried 2 of your examples and I get errors on both. This one gives me error:

Specified argument was out of the range of valid values. Parameter name: index
0
Jayesh Goyani
Top achievements
Rank 2
answered on 05 Aug 2011, 05:41 AM
Hello,

sorry this solution not worked properly.

To solve the "Specified argument was out of the range of valid values" error.

Please change index and check at which index you can get the textbox.

for example :
TextBox txt= edititem["ColumnUniqueName"].Controls[1] as TextBox;
TextBox txt= edititem["ColumnUniqueName"].Controls[2] as TextBox;
TextBox txt= edititem["ColumnUniqueName"].Controls[3] as TextBox;

Thanks,
Jayesh Goyani
0
Minh
Top achievements
Rank 1
answered on 08 Aug 2011, 07:06 AM
Hi,

on this I get

Error 7 'Telerik.Web.UI.GridEditableItem' is a 'type' but is used like a 'variable' C:\Development\GHG-MCA\GHG-MCA\WellVent.aspx.cs 394 13 GHG-MCA

 

 

protected void Unload_OnSelectedIndexChangedHandler(object sender, RadComboBoxSelectedIndexChangedEventArgs e)

 

{

 

 

DropDownList list = sender as DropDownList;

 

 

 

GridEditableItem = (GridEditableItem)list.NamingContainer;

 

 

 

 

//We set the Event Start and Event End based on the selected Value

 

 

 

if (e.Value == "51")

 

{

 

 

 

//TextBox txt = (TextBox)item["ColumnUniqueName"].Controls[0];

 

 

 

//txt.ReadOnly = true;

 

 

}

}

0
Princy
Top achievements
Rank 2
answered on 08 Aug 2011, 07:18 AM
Hello Minh,

You can set a column ReadOnly in SelectedIndexChanged event as shown below.
C#:
protected void ComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
       RadComboBox combo = sender as RadComboBox;
       GridEditableItem item = (GridEditableItem)combo.NamingContainer;
       TextBox txt = (TextBox)item["ColumnUniqueName"].Controls[0];
       txt.ReadOnly = true;
}

Thanks,
Princy.
0
Minh
Top achievements
Rank 1
answered on 08 Aug 2011, 10:10 AM
...it is for a GridDateTimeColumn and GridNumericColumn...The error message says

Error 9 Cannot convert type 'System.Web.UI.Control' to 'Telerik.Web.UI.GridDateTimeColumn' C:\Development\GHG-MCA\GHG-MCA\WellVent.aspx.cs 405 42 GHG-MCA


Error 9 Cannot convert type 'System.Web.UI.Control' to 'Telerik.Web.UI.GridNumericColumn' C:\Development\GHG-MCA\GHG-MCA\WellVent.aspx.cs 405 41 GHG-MCA

 

 

 

//Unload event

 

 

 

 

 

 

 

 

protected void Unload_OnSelectedIndexChangedHandler(object sender, RadComboBoxSelectedIndexChangedEventArgs e)

 

{

 

 

 

 

 

 

//We set the Event Start and Event End based on the selected Value

 

 

 

if (e.Value != "51")

 

{

 

 

RadComboBox combo = sender as RadComboBox;

 

 

 

GridEditableItem item = (GridEditableItem)combo.NamingContainer;

 

 

 

GridNumericColumn txt = (GridNumericColumn)item["EventStartDateTime"].Controls[0];

 

txt.ReadOnly =

 

true;

 

 

}

}

0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 08 Aug 2011, 10:39 AM
Hello,

GridNumericColumn txt = (GridNumericColumn)item["EventStartDateTime"].Controls[0];

please change above code line with below code.

RadDatePicker txt = (RadDatePicker)item["EventStartDateTime"].Controls[0];

let me know if any concern.


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Minh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Pierre
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Minh
Top achievements
Rank 1
Share this question
or