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

Different template for insert and edit

5 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
saravanan k
Top achievements
Rank 1
saravanan k asked on 29 Mar 2010, 02:36 PM
hi all,

I am new to telerik rad controls. i have a rad grid and a griddropdowncolumn in it. my requirement is i want this griddropdowncolumn as editable when i try to insert a new record. and the same column as readonly when i try to edit the record. i dont even know how to differentiate the insertmode and the editmode. kindly help me, by telling which handler to write the logic and also giving a small code snippet.

Regards,
Saravanan.K

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Mar 2010, 03:09 PM
Hello Saravanan,

You can differentiate insert/edit mode by checking e.CommandName inside ItemCommand event.Try the following code:

C#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    if (e.CommandName == RadGrid.EditCommandName) 
    { 
        (RadGrid1.MasterTableView.GetColumn("GridDropDownColumn1"as GridDropDownColumn).ReadOnly = true
    } 
    else if (e.CommandName == RadGrid.InitInsertCommandName) 
    { 
        (RadGrid1.MasterTableView.GetColumn("GridDropDownColumn1"as GridDropDownColumn).ReadOnly = false
    }  

Regards
Princy
0
saravanan k
Top achievements
Rank 1
answered on 30 Mar 2010, 06:05 AM
thanks a lot for the response. the solution worked. i have one more problem. i need to append an empty list item in the drop down. i tried the option enableemptylistitem = true and gave an empty list item. but it is not coming once the drop down is databound. is there any option like appenddatabounditems = true for this column?. kindly help..

Regards,
Saravanan K
0
Princy
Top achievements
Rank 2
answered on 30 Mar 2010, 08:12 AM
Hello,

For achieving this, you can access the drop down control and insert empty item inside ItemDataBound event as shown below.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
{  
if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
{  
 
   DropDownList dropDownList =  (DropDownList)editedItem["GridDropDownColumn1"].Controls[0];  
    dropDownList.Items.Insert(0, new ListItem(" "" "));  

Regards
Princy
0
saravanan k
Top achievements
Rank 1
answered on 30 Mar 2010, 09:24 AM
this snippet is not working. the error is "the editeditem doesnot exists in the current context". do i have to include any reference?

Regards,
Saravanan K
0
Princy
Top achievements
Rank 2
answered on 30 Mar 2010, 09:52 AM
Hi,

'editeditem' is of type GridEditableItem. you can get it from e.Item while grid is in edit mode. Try the following code.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
{             
    GridEditableItem editedItem = e.Item as GridEditableItem;            
    DropDownList dropDownList = (DropDownList)editedItem["GridDropDownColumn1"].Controls[0]; 
    dropDownList.Items.Insert(0, new ListItem(" "" ")); 
    

Thanks
Princy
Tags
Grid
Asked by
saravanan k
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
saravanan k
Top achievements
Rank 1
Share this question
or