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

Columns enabling vary for AddNew Record/Edit

1 Answer 34 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ESM Dev
Top achievements
Rank 1
ESM Dev asked on 29 May 2009, 05:39 PM
Hi,

In edit event only few columns to be allowed for editing and for AddNew record all columns to be allowed to enter values. GridColumns are autogenerated. Please reply with some solutions/suggestions.

Thanks
Venkat

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 30 May 2009, 06:25 AM
Hello Venkat,

Try the following approach:
<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource" 
    AutoGenerateEditColumn="true" OnItemCommand="RadGrid1_ItemCommand"
    <MasterTableView CommandItemDisplay="Top" /> 
</telerik:RadGrid> 

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    if (e.CommandName == RadGrid.EditCommandName) 
        (RadGrid1.MasterTableView.GetColumn("Date"as GridBoundColumn).ReadOnly = true
    if (e.CommandName == RadGrid.InitInsertCommandName) 
        (RadGrid1.MasterTableView.GetColumn("Date"as GridBoundColumn).ReadOnly = false

protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    (source as RadGrid).DataSource = GetData(); 

private DataTable GetData() 
    DataTable table = new DataTable(); 
    table.Columns.Add("ID"typeof(int)); 
    table.Columns.Add("Date"typeof(string)); 
    table.Columns.Add("Type"typeof(string)); 
    for (int i = 0; i < 10; i++) 
        table.Rows.Add(i, DateTime.Now.ToString(), i * DateTime.Now.Millisecond); 
    return table; 

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.
Tags
Grid
Asked by
ESM Dev
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or