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

[Solved] readonly property for radgrid column

9 Answers 441 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ying
Top achievements
Rank 1
Ying asked on 17 Jun 2009, 08:22 PM

I have a GridTemplateColumn for a radDatePicker,a GridHTMLEditorColumn, and a GridButtonColumn in my grid (see code below).  I need to make these columns show up in edit mode but invisible when doing insert. What kind of object I should cast them to in the _ItemCommand event so that I can set the readonly property?

<telerik:GridTemplateColumn HeaderText="Warrant Date" UniqueName="WarrantDate" 
    Visible="False" DataType="System.DateTime">  
    <EditItemTemplate> 
        <telerik:RadDatePicker ID="RadDatePicker1" runat="server" Skin="Office2007" allowEmpty="true" 
            Culture="English (United States)" DbSelectedDate='<%# Eval("WarrantDate") %>' > 
            <DateInput ID="DateInput1" LabelCssClass="radLabelCss_Office2007" Skin="Office2007" 
                runat="server">  
            </DateInput> 
            <Calendar ID="Calendar1" Skin="Office2007" UseColumnHeadersAsSelectors="False" runat="server" 
                UseRowHeadersAsSelectors="False" ViewSelectorText="x" ShowRowHeaders="false">  
            </Calendar> 
            <DatePopupButton /> 
        </telerik:RadDatePicker> 
    </EditItemTemplate> 
</telerik:GridTemplateColumn> 

<
telerik:GridButtonColumn ButtonType="PushButton" CommandName="ReOpenWarrant" ShowInEditForm="True" 
    Text="Re-Open Warrant" UniqueName="ReOpenWarrant" Visible="False" HeaderText="">  
    <ItemStyle ForeColor="White" /> 
</telerik:GridButtonColumn> 
<telerik:GridHTMLEditorColumn UniqueName="Charge" HeaderText="Charge" DataField="Charge">  
</telerik:GridHTMLEditorColumn>   

Thank you!
Ying

9 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Jun 2009, 07:04 AM
Hi Ying,

I hope you are trying to hide the column in the InsertForm and show it in the edit form. If so you may try out the following code snippet to achieve the desired scenario.

CS:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if ((e.Item is GridEditFormInsertItem) && (e.Item.OwnerTableView.IsItemInserted)) 
        {  
            GridEditFormInsertItem insertItem=(GridEditFormInsertItem)e.Item; 
            insertItem["WarrantDate"].Parent.Visible = false
            insertItem["ReOpenWarrant"].Parent.Visible = false
            insertItem["Charge"].Parent.Visible = false
 
        } 
   } 


Regards
Shinu.
0
Ying
Top achievements
Rank 1
answered on 18 Jun 2009, 04:21 PM

Shinu,

 

Thank you for your reply. I tried your code but the code never get executed. I have noticed that the following code will hide 'Charge' in both 'Insert' and 'Edit' mode. If only there is a way to know the mode, then I can do it properly.

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
{  
 
    //make Charge and ReOpenWarrant invisible for edit  
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)   
    {  
        GridEditableItem editItem = (GridEditableItem)e.Item;  
        editItem["Charge"].Parent.Visible = false;  
        editItem["ReOpenWarrant"].Parent.Visible = false;  
    }  
Another suggestions?
0
Ying
Top achievements
Rank 1
answered on 18 Jun 2009, 06:38 PM
I was able to find the Mode in _itemCommand event and save it in a private variable to pass to _ItemDataBound. Just wondering if there is some better way to do so.
0
Princy
Top achievements
Rank 2
answered on 19 Jun 2009, 06:45 AM
Hello Ying,

I am not sure as to what EditMode(InPlace/EditForms/PopUp) are you setting for the mastertableview but to check for the mode in ItemDataBound, you can try out the following code:
c#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    {        
       if (e.Item is GridEditableItem && e.Item.IsInEditMode)// will fire for both edit and insert modes when EditMode="EditForms" 
        { 
          ...... 
        }   
 
        //Replace GridEditableItem with GridDataInsertItem for EditMode="InPlace" 
       if (e.Item is GridEditableItem &&  e.Item.OwnerTableView.IsItemInserted)// will fire only for insert mode when EditMode="EditForms" 
        { 
            .....             
        } 
     } 

Hope this makes sense..
-Princy.
0
Ying
Top achievements
Rank 1
answered on 19 Jun 2009, 03:22 PM
Hello Princy,

Thank you so much! Your code is very helpful. Two additional questions:
1. what is the condition for 'fire only for edit when EditMode=EditForms'?
2. Is the condition the same for 'fire for both edit and insert' with EditMode=EditForms vs EditMode=InPlace?

Ying
0
Accepted
Daniel
Telerik team
answered on 19 Jun 2009, 07:42 PM
Hello Ying,

I hope the following information will be helpful to you.

  Edit mode
Insert mode
Browse mode
InPlace
GridDataItem
GridDataInsertItem
GridDataItem
EditForm GridEditFormItem
GridEditFormInsertItem
 GridDataItem

- e.Item is GridEditableItem is true in all modes, no matter whether the EditMode is InPlace or EditForms.
- e.Item.IsInEditMode is used to distinguish whether the item is in edit/insert mode (in all cases)
- e.Item.OwnerTableView.IsItemInserted applies to the tableview and not to specific item

Let us know if you need further details.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ying
Top achievements
Rank 1
answered on 19 Jun 2009, 08:39 PM
Thank you Daniel,

Your information is very helpful. As Princy indicated in his post
1.  if (e.Item is GridEditableItem && e.Item.IsInEditMode) // will fire for both edit and insert 

2.   if (e.Item is GridEditableItem &&  e.Item.OwnerTableView.IsItemInserted)// will fire only for insert 

Is there an explict condition for 'will fire only for edit' ? Or I can safely use 1 but not 2 for this condition?

0
Accepted
Daniel
Telerik team
answered on 19 Jun 2009, 09:37 PM
Hello Ying,

Depending on the EditMode you could use different approach:

Please note that you could use a single IF operator - I separated the conditions for better readability.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item.IsInEditMode)  //this covers edit and insert 
    { 
        if (!(e.Item is GridEditFormInsertItem)) //not in insert mode (EditMode="EditForms") 
        { 
            //do something 
        } 
    } 

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item.IsInEditMode)  //this covers edit and insert 
    { 
        if (!(e.Item is GridDataInsertItem)) //not in insert mode (EditMode="InPlace") 
        { 
            //do something 
        } 
    } 

Regarding your question:
"e.Item is GridEditableItem &&  e.Item.OwnerTableView.IsItemInserted"

The unwanted effect with this condition is that it will be executed N times if the OwnerTableView (MasterTableView for example) is in Insert mode. In other words - e.Item is GridEditableItem is true for every data item in RadGrid.

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ying
Top achievements
Rank 1
answered on 19 Jun 2009, 09:52 PM
Thank you so much Daniel,

I think you covered everything for me :)
Tags
Grid
Asked by
Ying
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ying
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Daniel
Telerik team
Share this question
or