dynamic - Getting the values of a dynamically created control inside Telerik:RadGrid -
i have telerik radgrid adding columns dynamically on click of button. code follows :
private void addcolumns() { try { datatable dtparmaintenancelistheaderdata = (datatable)session["parmaintenancelistheaderdata"]; foreach (datacolumn dc in dtparmaintenancelistheaderdata.columns) { dc.readonly = false; } if (!dtparmaintenancelistheaderdata.columns.contains("parcombodatafield")) dtparmaintenancelistheaderdata.columns.add("parcombodatafield", typeof(string)); dtparmaintenancelistheaderdata.acceptchanges(); foreach (datarow dreachrow in dtparmaintenancelistheaderdata.rows) { string cuscombo = dreachrow["cusfstnam"].tostring() + " - " + dreachrow["cuslstnam"].tostring(); string parcombo = dreachrow["parcod"].tostring() + " - " + dreachrow["pardsc"].tostring(); dreachrow["parcombodatafield"] = cuscombo + " " + parcombo; gridtemplatecolumn templatecolumn = new gridtemplatecolumn(); string templatecolumnname = cuscombo + " - " + parcombo; templatecolumn.itemtemplate = new radgridtemplate(templatecolumnname); templatecolumn.headertext = templatecolumnname; templatecolumn.datafield = "parqty"; templatecolumn.headerstyle.horizontalalign = horizontalalign.center; templatecolumn.itemstyle.horizontalalign = horizontalalign.center; templatecolumn.headerstyle.width = unit.pixel(60); templatecolumn.headerstyle.wrap = true; this.radgridparlistitems.mastertableview.columns.add(templatecolumn); } } catch (exception ex) { } }
the above method called on click of button.
in each of columns added adding textbox follows :
#region namespaces used using system; using system.web; using system.collections.generic; using system.web.ui; using system.web.ui.webcontrols; using system.data; using telerik.web.ui; #endregion /// <summary> /// summary description radgridtemplate /// </summary> public class radgridtemplate : itemplate { protected literalcontrol lcontrol; protected textbox textbox; private string colname; public radgridtemplate(string cname) { colname = cname; } public void instantiatein(system.web.ui.control container) { textbox = new textbox(); textbox.id = container.id + "txtparqty"; textbox.width = unit.pixel(50); container.controls.add(textbox); textbox.text = httpcontext.current.request.form[textbox.uniqueid]; } }
now there button,"save" when clicked upon have fetch data textboxes in dynamically added controls. trouble :
on post controls cleared , re-created values null.
how capture values of textboxes in row.
if instantiate template columns on init explained in telerik docs here, should able keep state steady on posbacks , fetch data textboxes looping through grid rows.
Comments
Post a Comment