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

RadGrid: Edit mode

2 Answers 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Siva
Top achievements
Rank 1
Siva asked on 31 Oct 2012, 12:52 PM
How to set EditFormColumnIndex for autogeneratedcolumns in radgrid. radgrid doesn't have any static headers by default.
I am using:

 protected void rgControl_PreRender(object sender, EventArgs e)
    {
                int j = 0, k = 1;
                foreach (GridColumn gc in rgControl.MasterTableView.AutoGeneratedColumns)
                {
                    if (j < k * 7)
                    {
                        gc.EditFormColumnIndex = k - 1;
                    }
                    else
                    {
                        k++;
                        gc.EditFormColumnIndex = k - 1;
                    }
                    j++;
                }
}
It works good but when i am edit a record it shows the following error: Sys.WebForms.PageRequestManagerServerErrorException: Editor cannot be initialized for column:5.

2 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 05 Nov 2012, 09:05 AM
Hi,

 You should also set the ColumnNumber property of the of the EditFormSettings in the MasterTableView. It specifies how many groups of columns you will have in the autogenerated edit form, the default is 1 and you have to set bigger value if you need to set different EditFormIndexes.
Below is a sample code to illustrate this approach:

<telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="true"
            AutoGenerateEditColumn="true">
            <MasterTableView>
                <EditFormSettings ColumnNumber="2" />
            </MasterTableView>
        </telerik:RadGrid>
protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
        RadGrid1.ColumnCreated += new GridColumnCreatedEventHandler(RadGrid1_ColumnCreated);
    }
 
    void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
    {
        if (e.Column.UniqueName == "Name" || e.Column.UniqueName == "Age")
        {
            e.Column.EditFormColumnIndex = 1;
        }
    }
 
    void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        DataTable t = new DataTable();
        t.Columns.Add("Name");
        t.Columns.Add("Age", typeof(int));
        t.Columns.Add("Note");
        t.Columns.Add("Test");
 
        for (int i = 0; i < 8; i++)
        {
            var r = t.NewRow();
            r["Name"] = "Name" + i;
            r["Age"] = i;
            r["Note"] = "Note" + i;
            r["Test"] = "Test" + i;
            t.Rows.Add(r);
        }
 
        RadGrid1.DataSource = t;
    }

Kind regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Siva
Top achievements
Rank 1
answered on 07 Nov 2012, 05:52 AM
Thank you very much for your reply.

By setting columnnumber in aspx my problem was solved.
Tags
Grid
Asked by
Siva
Top achievements
Rank 1
Answers by
Marin
Telerik team
Siva
Top achievements
Rank 1
Share this question
or