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

Need to diable some controls inside edit form based on some condition

1 Answer 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pams
Top achievements
Rank 1
Pams asked on 14 Jun 2011, 04:20 PM
Hi,
I am using radgrid to display user information.( name, position, company, IsExternal, IsPreferred)
Each row will have edit button.
When user clicks edit button, if that user is external user, the all fields will be editable.
If the user is Internal user, then only Ispreferred should be editable, and all other fields should be readonly.

Any help pls,
Thanks,
pams

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 Jun 2011, 07:56 AM
Hello Pams,

I suppose you are using BoundColumns. Try the following code in ItemCreated event to set ReadOnly for required fields.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
  if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
   {
       if (UserName == "Internal user")
      {
                GridEditFormItem item = (GridEditFormItem)e.Item;
                TextBox txtbx = (TextBox)item["Name"].Controls[0];
                txtbx.ReadOnly = true;
                TextBox txtbx1 = (TextBox)item["Position"].Controls[0];
                txtbx1.ReadOnly = true;
                TextBox txtbx2 = (TextBox)item["company"].Controls[0];
                txtbx2.ReadOnly = true;
                TextBox txtbx3 = (TextBox)item["IsExternal"].Controls[0];
                txtbx3.ReadOnly = true;
        }
    }
  }

Also check the following help documentation.
Accessing cells and rows.

Note: If you are using TemplateColumns, then access the columns using FindControl method.

Thanks,
Princy.
Tags
Grid
Asked by
Pams
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or