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

Make a cell read only based on its value (from db)

5 Answers 84 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Naresh
Top achievements
Rank 1
Naresh asked on 20 Nov 2008, 01:55 PM
hi
how to make a cell read only (not the whole column) based on the value of the cell or some other value from the db in that row

Naresh

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 20 Nov 2008, 02:29 PM
Hello Naresh,

I suppose you mean to disable a control in Edit mode depending on the specific value.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    Hashtable table = new Hashtable(); 
    GridEditFormItem item = e.Item as GridEditFormItem; //GridDataItem for InPlace 
    if (item != null && item.IsInEditMode) 
    { 
        item.ExtractValues(table); 
        string value = table["yourColumnName"].ToString(); 
        if (value == "Beverages"
            (item["yourColumnName"].Controls[0] as TextBox).ReadOnly = true
    } 

Let me know if I missed something.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Naresh
Top achievements
Rank 1
answered on 21 Nov 2008, 08:03 AM
hello,
Dim item As GridEditFormItem = TryCast(e.Item, GridEditFormItem)

e.item is GridDataItem
item is nothing
0
Accepted
Daniel
Telerik team
answered on 21 Nov 2008, 09:54 AM
Hello Naresh,

If the EditMode property is set to InPlace the item will be GridDataItem.
<MasterTableView EditMode="InPlace"... 

Otherwise if EditForms mode is used the item will be GridEditFormItem
<MasterTableView EditMode="EditForms"... 

Protected Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As GridItemEventArgs) 
    Dim table As New Hashtable() 
    Dim item As GridEditFormItem = TryCast(e.Item, GridEditFormItem) 
    'GridDataItem for InPlace  
    If item <> Nothing AndAlso item.IsInEditMode Then 
        item.ExtractValues(table) 
        Dim value As String = table("yourColumnName").ToString() 
        If value = "Beverages" Then 
            (TryCast(item("yourColumnName").Controls(0), TextBox)).[ReadOnly] = True 
        End If 
    End If 
End Sub 

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Naresh
Top achievements
Rank 1
answered on 21 Nov 2008, 10:49 AM
i don't know why i couldn't see that simple mistake :D
but thanks, this is the solution to my problem.
0
Shinu
Top achievements
Rank 2
answered on 21 Nov 2008, 11:43 AM
Hi Naresh,

You can also go through the following help articles to get more details about editmodes in RadGrid.
In place
Edit forms

Shinu.
Tags
Grid
Asked by
Naresh
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Naresh
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or