I am adding rows as columns after getting value from dropdown, i page is posted back i am not able to getting the textboxes in template columns, after selecting dropdown value storing in to the session and redirecting to the same page. if do like that ,columns keep on adding when page is posted back every time. can u provide me any solutions..
protected void Page_Init(object sender, EventArgs e)
{
string strPlant = string.Empty;
if (Session["PlantVal"] != null)
{
strPlant = Session["PlantVal"].ToString();
// Session["PlantVal"] = null;
//strPlant = cPlantGroup.SelectedValue;
if (strPlant != null && strPlant.Trim().Length > 0)
{
DefineGridStructure(strPlant);
}
}
}
public DataTable DefineGridStructure(string strPlant)
{
dtRaleLoad = new DataTable();
//RadGrid1.MasterTableView.AutoGenerateColumns = true;
//RadGrid1.MasterTableView.EnableColumnsViewState = true;
Plants oplant = new Plants();
GridBoundColumn boundColumn = new GridBoundColumn();
dtRaleLoad.Columns.Add("Date", typeof(string));
this.RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField = "Date";
boundColumn.UniqueName = "Date";
boundColumn.HeaderText = "Date";
boundColumn.DataType = System.Type.GetType("System.String");
GridBoundColumn boundColumn1;
DataSet ds = new DataSet();
ds = oplant.GetChildCode(strPlant);
string strChildCode = ds.Tables[0].Rows[0][0].ToString();
Session["ChildCode"] = strChildCode;
DataTable dtgroup = new DataTable();
string strgroup = strChildCode;
dtgroup = oplant.GetPlant(strgroup);
DataRow dtRow = null;
if (dtgroup != null)
{
foreach (DataRow dr in dtgroup.Rows)
{
String sPlantName = "";
String sPlantCode = "";
//sPlantName = dr["PlantName1"].ToString();
sPlantCode = dr["PlantCode"].ToString();
dtRaleLoad.Columns.Add(sPlantCode, typeof(string));
boundColumn1 = new GridBoundColumn();
this.RadGrid1.MasterTableView.Columns.Add(boundColumn1);
boundColumn1.DataField = sPlantCode;
boundColumn1.UniqueName = sPlantCode;
boundColumn1.HeaderText = sPlantCode;
boundColumn1.DataType = System.Type.GetType("System.String");
}
}
string templateColumnName = "Total";
GridTemplateColumn templateColumn = new GridTemplateColumn();
dtRaleLoad.Columns.Add("Total", typeof(string));
templateColumn.ItemTemplate = new MyTemplate1(templateColumnName);
this.RadGrid1.MasterTableView.Columns.Add(templateColumn);
templateColumn.UniqueName = "Total";
templateColumn.DataField = "Total";
templateColumn.HeaderText = "Total";
templateColumn.DataType = System.Type.GetType("System.String");
DataTable dtport = new DataTable();
dtport = oplant.GetPortName(strgroup);
GridTemplateColumn templateColumn1;
if (dtport != null)
{
foreach (DataRow dr in dtport.Rows)
{
string sPortName = "";
string sPortCode = "";
sPortName = dr["PortName"].ToString();
sPortCode = dr["PortCode"].ToString();
dtRaleLoad.Columns.Add(sPortName, typeof(string));
templateColumn1 = new GridTemplateColumn();
this.RadGrid1.MasterTableView.Columns.Add(templateColumn1);
templateColumn1.ItemTemplate = new TemplatePort(sPortCode);
templateColumn1.DataField = sPortName;
templateColumn1.UniqueName = sPortName;
templateColumn1.HeaderText = sPortName;
templateColumn1.DataType = System.Type.GetType("System.String");
}
}
string templateColumnName2 = "UnAllot";
GridTemplateColumn templateColumn2 = new GridTemplateColumn();
dtRaleLoad.Columns.Add("UnAllot", typeof(string));
templateColumn2.ItemTemplate = new MyTemplate3(templateColumnName2);
this.RadGrid1.MasterTableView.Columns.Add(templateColumn2);
templateColumn2.UniqueName = "Unallot";
templateColumn2.HeaderText = "UnAllot";
templateColumn2.DataField = "UnAllot";
templateColumn2.DataType = System.Type.GetType("System.String");
string templateColumnName3 = "Rake";
GridTemplateColumn templateColumn3 = new GridTemplateColumn();
dtRaleLoad.Columns.Add("Rake", typeof(string));
templateColumn3.ItemTemplate = new MyTemplate4(templateColumnName3);
this.RadGrid1.MasterTableView.Columns.Add(templateColumn3);
templateColumn3.DataField = "Rake";
templateColumn3.UniqueName = "Rake";
templateColumn3.HeaderText = "Rake";
templateColumn3.DataField = "Rake";
templateColumn3.DataType = System.Type.GetType("System.String");
Session["Rake"] = dtRaleLoad;
RadGrid1.DataSource = dtRaleLoad;
return dtRaleLoad;
}
private class MyTemplate1 : ITemplate
{
protected TextBox txtTotal;
private string colname1;
public MyTemplate1(string cName)
{
colname1 = cName;
txtTotal = new TextBox();
txtTotal.ID = colname1;
txtTotal.Visible = true;
System.Web.UI.Control container1 = new System.Web.UI.Control();
container1.Controls.Add(txtTotal);
}
public void InstantiateIn(Control container)
{
txtTotal = new TextBox();
//txtTotal.ReadOnly = true;
txtTotal.ID = colname1;
container.Controls.Add(txtTotal);
}
}
private class MyTemplate2 : ITemplate
{
protected TextBox txtPort;
private string colname2;
public MyTemplate2(string cName)
{
colname2 = cName;
txtPort = new TextBox();
txtPort.ID = colname2;
txtPort.Visible = true;
System.Web.UI.Control container3 = new System.Web.UI.Control();
container3.Controls.Add(txtPort);
}
public void InstantiateIn(System.Web.UI.Control container)
{
txtPort = new TextBox();
txtPort.ID = colname2;
container.Controls.Add(txtPort);
}
}
private class MyTemplate3 : ITemplate
{
protected TextBox txtUnAllot;
private string colname3;
public MyTemplate3(string cName)
{
colname3 = cName;
txtUnAllot = new TextBox();
txtUnAllot.ID = colname3;
System.Web.UI.Control container4 = new System.Web.UI.Control();
container4.Controls.Add(txtUnAllot);
}
public void InstantiateIn(System.Web.UI.Control container)
{
txtUnAllot = new TextBox();
txtUnAllot.ID = colname3;
container.Controls.Add(txtUnAllot);
}
}
private class MyTemplate4 : ITemplate
{
protected TextBox txtRake;
private string colname4;
public MyTemplate4(string cName)
{
colname4 = cName;
txtRake = new TextBox();
txtRake.ID = colname4;
System.Web.UI.Control container2 = new System.Web.UI.Control();
container2.Controls.Add(txtRake);
}
public void InstantiateIn(System.Web.UI.Control container)
{
txtRake = new TextBox();
txtRake.ID = colname4;
container.Controls.Add(txtRake);
}
}
protected void Page_Init(object sender, EventArgs e)
{
string strPlant = string.Empty;
if (Session["PlantVal"] != null)
{
strPlant = Session["PlantVal"].ToString();
// Session["PlantVal"] = null;
//strPlant = cPlantGroup.SelectedValue;
if (strPlant != null && strPlant.Trim().Length > 0)
{
DefineGridStructure(strPlant);
}
}
}
public DataTable DefineGridStructure(string strPlant)
{
dtRaleLoad = new DataTable();
//RadGrid1.MasterTableView.AutoGenerateColumns = true;
//RadGrid1.MasterTableView.EnableColumnsViewState = true;
Plants oplant = new Plants();
GridBoundColumn boundColumn = new GridBoundColumn();
dtRaleLoad.Columns.Add("Date", typeof(string));
this.RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField = "Date";
boundColumn.UniqueName = "Date";
boundColumn.HeaderText = "Date";
boundColumn.DataType = System.Type.GetType("System.String");
GridBoundColumn boundColumn1;
DataSet ds = new DataSet();
ds = oplant.GetChildCode(strPlant);
string strChildCode = ds.Tables[0].Rows[0][0].ToString();
Session["ChildCode"] = strChildCode;
DataTable dtgroup = new DataTable();
string strgroup = strChildCode;
dtgroup = oplant.GetPlant(strgroup);
DataRow dtRow = null;
if (dtgroup != null)
{
foreach (DataRow dr in dtgroup.Rows)
{
String sPlantName = "";
String sPlantCode = "";
//sPlantName = dr["PlantName1"].ToString();
sPlantCode = dr["PlantCode"].ToString();
dtRaleLoad.Columns.Add(sPlantCode, typeof(string));
boundColumn1 = new GridBoundColumn();
this.RadGrid1.MasterTableView.Columns.Add(boundColumn1);
boundColumn1.DataField = sPlantCode;
boundColumn1.UniqueName = sPlantCode;
boundColumn1.HeaderText = sPlantCode;
boundColumn1.DataType = System.Type.GetType("System.String");
}
}
string templateColumnName = "Total";
GridTemplateColumn templateColumn = new GridTemplateColumn();
dtRaleLoad.Columns.Add("Total", typeof(string));
templateColumn.ItemTemplate = new MyTemplate1(templateColumnName);
this.RadGrid1.MasterTableView.Columns.Add(templateColumn);
templateColumn.UniqueName = "Total";
templateColumn.DataField = "Total";
templateColumn.HeaderText = "Total";
templateColumn.DataType = System.Type.GetType("System.String");
DataTable dtport = new DataTable();
dtport = oplant.GetPortName(strgroup);
GridTemplateColumn templateColumn1;
if (dtport != null)
{
foreach (DataRow dr in dtport.Rows)
{
string sPortName = "";
string sPortCode = "";
sPortName = dr["PortName"].ToString();
sPortCode = dr["PortCode"].ToString();
dtRaleLoad.Columns.Add(sPortName, typeof(string));
templateColumn1 = new GridTemplateColumn();
this.RadGrid1.MasterTableView.Columns.Add(templateColumn1);
templateColumn1.ItemTemplate = new TemplatePort(sPortCode);
templateColumn1.DataField = sPortName;
templateColumn1.UniqueName = sPortName;
templateColumn1.HeaderText = sPortName;
templateColumn1.DataType = System.Type.GetType("System.String");
}
}
string templateColumnName2 = "UnAllot";
GridTemplateColumn templateColumn2 = new GridTemplateColumn();
dtRaleLoad.Columns.Add("UnAllot", typeof(string));
templateColumn2.ItemTemplate = new MyTemplate3(templateColumnName2);
this.RadGrid1.MasterTableView.Columns.Add(templateColumn2);
templateColumn2.UniqueName = "Unallot";
templateColumn2.HeaderText = "UnAllot";
templateColumn2.DataField = "UnAllot";
templateColumn2.DataType = System.Type.GetType("System.String");
string templateColumnName3 = "Rake";
GridTemplateColumn templateColumn3 = new GridTemplateColumn();
dtRaleLoad.Columns.Add("Rake", typeof(string));
templateColumn3.ItemTemplate = new MyTemplate4(templateColumnName3);
this.RadGrid1.MasterTableView.Columns.Add(templateColumn3);
templateColumn3.DataField = "Rake";
templateColumn3.UniqueName = "Rake";
templateColumn3.HeaderText = "Rake";
templateColumn3.DataField = "Rake";
templateColumn3.DataType = System.Type.GetType("System.String");
Session["Rake"] = dtRaleLoad;
RadGrid1.DataSource = dtRaleLoad;
return dtRaleLoad;
}
private class MyTemplate1 : ITemplate
{
protected TextBox txtTotal;
private string colname1;
public MyTemplate1(string cName)
{
colname1 = cName;
txtTotal = new TextBox();
txtTotal.ID = colname1;
txtTotal.Visible = true;
System.Web.UI.Control container1 = new System.Web.UI.Control();
container1.Controls.Add(txtTotal);
}
public void InstantiateIn(Control container)
{
txtTotal = new TextBox();
//txtTotal.ReadOnly = true;
txtTotal.ID = colname1;
container.Controls.Add(txtTotal);
}
}
private class MyTemplate2 : ITemplate
{
protected TextBox txtPort;
private string colname2;
public MyTemplate2(string cName)
{
colname2 = cName;
txtPort = new TextBox();
txtPort.ID = colname2;
txtPort.Visible = true;
System.Web.UI.Control container3 = new System.Web.UI.Control();
container3.Controls.Add(txtPort);
}
public void InstantiateIn(System.Web.UI.Control container)
{
txtPort = new TextBox();
txtPort.ID = colname2;
container.Controls.Add(txtPort);
}
}
private class MyTemplate3 : ITemplate
{
protected TextBox txtUnAllot;
private string colname3;
public MyTemplate3(string cName)
{
colname3 = cName;
txtUnAllot = new TextBox();
txtUnAllot.ID = colname3;
System.Web.UI.Control container4 = new System.Web.UI.Control();
container4.Controls.Add(txtUnAllot);
}
public void InstantiateIn(System.Web.UI.Control container)
{
txtUnAllot = new TextBox();
txtUnAllot.ID = colname3;
container.Controls.Add(txtUnAllot);
}
}
private class MyTemplate4 : ITemplate
{
protected TextBox txtRake;
private string colname4;
public MyTemplate4(string cName)
{
colname4 = cName;
txtRake = new TextBox();
txtRake.ID = colname4;
System.Web.UI.Control container2 = new System.Web.UI.Control();
container2.Controls.Add(txtRake);
}
public void InstantiateIn(System.Web.UI.Control container)
{
txtRake = new TextBox();
txtRake.ID = colname4;
container.Controls.Add(txtRake);
}
}