<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
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