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

dynamic row wanted copy previous row and create same row again in radgrid

1 Answer 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 14 May 2012, 06:16 PM
      <telerik:RadGrid ID="RadGrid1" runat="server"
            Width="950px" oninsertcommand="RadGrid1_InsertCommand" 
            onitemcommand="RadGrid1_ItemCommand" onitemcreated="RadGrid1_ItemCreated" 
            oniteminserted="RadGrid1_ItemInserted" 
            onneeddatasource="RadGrid1_NeedDataSource" CellSpacing="0" 
            GridLines="None">
       <MasterTableView  EditMode="InPlace"   >
<CommandItemSettings ExportToPdfText="Export to PDF" ></CommandItemSettings>


<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>


<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
       <Columns><telerik:GridTemplateColumn UniqueName="ADDCombo"><%--<ItemTemplate></ItemTemplate>--%></telerik:GridTemplateColumn></Columns>


<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
       </MasterTableView>


<FilterMenu EnableImageSprites="False"></FilterMenu>


<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>
        </telerik:RadGrid>


and on code behind i am creating a dynamic row like that

    public void bindcontroltogrid(RadGrid gridtobind, RadTextBox rdtextgrid, RadComboBox rdcmbgrid)
        {
         
            int j = 0;
            string[] a = {"a" };
            gridtobind.DataSource = null;
            lstvisiblelement = (List<TransactionSetupDL.TrTypeAttrDL>)HttpContext.Current.Session["lstvisiblelementofgrid"];
            gridtobind.MasterTableView.DataSource = a;
            gridtobind.MasterTableView.TableLayout = GridTableLayout.Auto;
            gridtobind.ClientSettings.Scrolling.AllowScroll = true;
            gridtobind.ClientSettings.Scrolling.ScrollHeight = 100;
            gridtobind.MasterTableView.ShowHeadersWhenNoRecords = true;
            gridtobind.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = true;
            gridtobind.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
            gridtobind.MasterTableView.EditMode = GridEditMode.InPlace;
            gridtobind.AllowAutomaticDeletes = true;
            gridtobind.AutoGenerateDeleteColumn = true;
            gridtobind.AutoGenerateEditColumn = true;
            
          
            Control container = new Control();
            for (int i = 0; i < lstvisiblelement.Count; i++)
            {
                GridTemplateColumn tc = new GridTemplateColumn();
                ControlType = (BaseBLDL.Global.controlType)lstvisiblelement[i].ControlType;
                switch (ControlType)
                {
                    case BaseBLDL.Global.controlType.bpTxtControl:








                        tc.ItemTemplate = new AddTemplateToGridView(ControlType, lstvisiblelement[i].DefaultVal, lstvisiblelement[i].AttrDefId, lstvisiblelement[i].Editable, rdcmbgrid, rdtextgrid);
                      






                        tc.ItemTemplate.InstantiateIn(container);
           




                        //  gridtobind.MasterTableView.Columns[j].HeaderStyle.Width = lstvisiblelement[i].ColWidth;
                        gridtobind.MasterTableView.Columns.AddAt(j, tc);
                        gridtobind.MasterTableView.Columns[j].HeaderText = lstvisiblelement[i].Label;


                        break;
                    case BaseBLDL.Global.controlType.bpCmbControl:












                        tc.ItemTemplate = new AddTemplateToGridView(ControlType, lstvisiblelement[i].DefaultVal, lstvisiblelement[i].AttrDefId, lstvisiblelement[i].Editable, rdcmbgrid, rdtextgrid);




                        Control containercmb = new Control();


                        tc.ItemTemplate.InstantiateIn(containercmb);


                        //  gridtobind.MasterTableView.Columns[j].ItemStyle.Width = lstvisiblelement[i].ColWidth;




                        gridtobind.MasterTableView.Columns.AddAt(j, tc);
                        gridtobind.MasterTableView.Columns[j].HeaderText = lstvisiblelement[i].Label;


                    
                        break;


                }
                j++;


            }
            gridtobind.Rebind();
            
        }
        public class AddTemplateToGridView : ITemplate
        {
            ListItemType _type;
            string _colName;
            string _DefaultVal;
            int _AttrDefId;
            bool _Editable;
            BaseBLDL.Global.controlType _controltype;
            RadComboBox _cmboxgrid;
            RadTextBox _rdtextbox;
            //ListItemType type, string colname,
            public AddTemplateToGridView(BaseBLDL.Global.controlType controltype, string DefaultVal, int AttrDefId, bool Editable, RadComboBox cmboxgrid, RadTextBox rdtextbox)
            {
                //_type = type;


                //_colName = colname;
                _controltype = controltype;
                _DefaultVal = DefaultVal;
                _AttrDefId = AttrDefId;
                _Editable = Editable;
                _cmboxgrid = cmboxgrid;
                _rdtextbox = rdtextbox;
            }
            void ITemplate.InstantiateIn(System.Web.UI.Control container)
            {




                switch (_controltype)
                {
                    case BaseBLDL.Global.controlType.bpTxtControl:
                        if (_AttrDefId == 13)
                        {
                            Label lb = new Label();
                            lb.Text = "1";


                            container.Controls.Add(lb);
                        }
                        else
                        {
                            _rdtextbox = new RadTextBox();


                            _rdtextbox.Text = _DefaultVal;
                            _rdtextbox.Enabled = _Editable;


                            container.Controls.Add(_rdtextbox);
                        }
                        break;


                    case BaseBLDL.Global.controlType.bpCmbControl:
                        if (_AttrDefId == 17)
                        {
                            _rdtextbox = new RadTextBox();
                            _rdtextbox.Text = _DefaultVal;
                            container.Controls.Add(_rdtextbox);
                        }
                        else
                        {
                            _cmboxgrid = new RadComboBox();


                            _cmboxgrid.Items.Add(new RadComboBoxItem("Select Item"));


                            container.Controls.Add(_cmboxgrid);
                        }
                        break;
                }


            }

now i want to create same row again on add new record button click that is previously created on the code that i above posted 
with combo box and textbox controls kindly help

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 17 May 2012, 04:08 PM
As far as I understand you need your custom template applied to the edit/insert form of the grid. If this is the case, do follow the guidelines in the following help topic:
http://www.telerik.com/help/aspnet-ajax/grid-custom-edit-forms.html

(section: Creating FormTemplate custom edit form programmatically)

Hope it helps.

Greetings,
Tsvetoslav
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
Muhammad
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or