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

Grid Make every row editable with GridDropDownColumn

2 Answers 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 10 Jun 2014, 08:24 PM
Hi,

I'm using the RadGrid to populate a list of objects; Document.
I'll like to make every row editable, but currently only the last row has the GridDropDownColumn enabled.

Please help!.
Thanks!

<telerik:RadGrid ID="RadGridDocuments" runat="server" CellSpacing="-1" GridLines="Both"
                AutoGenerateColumns="false" OnItemDataBound="RadGridDocuments_ItemDataBound"
                OnPreRender="RadGridDocuments_PreRender">
                <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">
                    <Selecting AllowRowSelect="True" />
                </ClientSettings>
                <MasterTableView EditMode="InPlace">
                    <Columns>
                        <telerik:GridBoundColumn DataField="FileName" HeaderText="File Name" UniqueName="FileName"
                            ReadOnly="true">
                        </telerik:GridBoundColumn>
                        <telerik:GridDropDownColumn UniqueName="Type" HeaderText="Type" DataField="Type"
                            EmptyListItemText="--Choose an option--" EmptyListItemValue="">
                        </telerik:GridDropDownColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>

protected void ButtonAddDetails_Click(object sender, EventArgs e)
       {
             
           List<Document> docs = new List<Document>();
           foreach (UploadedFile f in RadAsyncUploadDocuments.UploadedFiles)
           {
               docs.Add(new Document(f));
           }
           RadGridDocuments.DataSource = docs;
           RadGridDocuments.DataBind();
       }
       protected void RadGridDocuments_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
       {
           if (e.Item is GridEditableItem && e.Item.IsInEditMode)
           {
               GridEditableItem editedItem = e.Item as GridEditableItem;
               GridEditManager editMan = editedItem.EditManager;
               GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("Type"));
               //in case you have RadComboBox editor for the GridDropDownColumn (this is the default editor),  
               //you will need to use ComboBoxControl below instead of DropDownListControl   
               //and add RadComboBoxItems instead of ListItems to the Items collection of the editor
               editor.ComboBoxControl.Items.Add(new RadComboBoxItem("FAA Administrator's Order", "FAA Administrator's Order"));
               editor.ComboBoxControl.Items.Add(new RadComboBoxItem("Notice of Appeal", "Notice of Appeal"));
           }
       }
       protected void RadGridDocuments_PreRender(object sender, System.EventArgs e)
       {
           foreach (GridItem item in RadGridDocuments.MasterTableView.Items)
           {
               if (item is GridEditableItem)
               {
                   GridEditableItem editableItem = item as GridDataItem;
                   editableItem.Edit = true;
               }
           }
           RadGridDocuments.Rebind();
       }

public class Document
    {
        private UploadedFile file;
        private string type;
  
        public Document(UploadedFile file)
        {
            this.file = file;
            this.type = string.Empty;
        }
  
        public UploadedFile File
        {
            get
            {
                return this.file;
            }
        }
  
        public string FileName
        {
            get
            {
                return this.file.FileName;
            }
        }
  
        public string Type
        {
            get
            {
                return this.type;
            }
            set
            {
                this.type = value;
            }
        }
  
    }










2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Jun 2014, 05:37 AM
Hi Steve,

Please set AllowMultiRowEdit="true for your RadGrid to have multiple rows in edit.

ASPX:
<telerik:RadGrid ID="RadGridDocuments"  AllowMultiRowEdit="true". . . >

Thanks,
Shinu
0
Steve
Top achievements
Rank 1
answered on 11 Jun 2014, 01:20 PM
Thanks! that was so helpful.
Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Steve
Top achievements
Rank 1
Share this question
or