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

Programmatically Add Edit Column

1 Answer 184 Views
Grid
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 29 Feb 2012, 04:08 PM
I have an ASP DetailsView with a RadGrid in one of the Template Columns. What I would like to do is when I put my DetailsView into edit mode to add the edit and delete columns to the RadGrid. Right now I have it so in the DataBound event for the DetailsView I check if it's in edit mode and then add the "Add New Record" button. I have tried adding code to turn on the edit column but it doesn't work. See the code example below. Any help would be appreciated.

if(((DetailsView)sender).CurrentMode== DetailsViewMode.Edit)
            {
                DropDownList ddl = (DropDownList)((DetailsView)sender).FindControl("DevicesLocation");
                Label lbl = (Label)((DetailsView)sender).FindControl("lblLocationID");
 
                LocationDropDown(ddl);
                ddl.SelectedValue = lbl.Text;
 
    // Show the command display on edit
                ipAddressRadGrid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;

      // Add edit column
                ipAddressRadGrid.AutoGenerateEditColumn = true;
 
                ipAddressRadGrid.Rebind();
            }

1 Answer, 1 is accepted

Sort by
0
Accepted
Antonio Stoilkov
Telerik team
answered on 05 Mar 2012, 12:22 PM
Hello William,

You could implement the desired functionality by defining GridEditCommandColumn and setting its Visible property to false. If the DetailsView CurrentMode is Edit set the Visible property to true. Note that setting AutoGenerateEditColumn will take effect only if called on OnPageLoad or OnPageInit events.
<telerik:GridEditCommandColumn UniqueName="EditColumn" Visible="false" />
this.RadGrid1.MasterTableView.GetColumn("EditColumn").Visible = true;

Regards,
Antonio Stoilkov
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.
Tags
Grid
Asked by
William
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Share this question
or