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

[Solved] Set default values for new rows in grid

1 Answer 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris Smith
Top achievements
Rank 1
Chris Smith asked on 29 Oct 2009, 08:55 PM
Experienced members,

I must be missing what is right in front of me... How does one go about setting a default value on newly inserted rows in the grid.

I have tried many of the events to get to e.Item.DataItem but alot of the time that property is null.

Can anyone point me in the right direction here?

Thanks,

Chris

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Oct 2009, 06:01 AM
Hi,


Try the code snippet below  to set default values for the insert form

C#

protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)  
{  
if (e.CommandName == RadGrid.InitInsertCommandName)  
{  
 // cancel the default operation  
 e.Canceled = true;  
 
 //Prepare an IDictionary with the predefined values  
 System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();  
 newValues["ContactName"] = "default contact name";  
 newValues["CompanyName"] = " default company name";  
 
 //set default value for the dropdown list inside the EditItemTemplate  
 newValues["Country"] = "Germany";  
 
 //set default checked state for the checkbox inside the EditItemTemplate  
 newValues["Bool"] = false;  
 
 //Insert the item and rebind  
 e.Item.OwnerTableView.InsertItem(newValues);  
 
}  
}  


For more information on the same
Inserting values in-place and EditForms

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