Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > InstantiateIn doesn't execute without .DataBind

Reply
Thread Tools

InstantiateIn doesn't execute without .DataBind

 
 
Oleg Ogurok
Guest
Posts: n/a
 
      12-02-2003
Hi all,

I'm adding several TemplateColumns to my grid programmatically in Page_Load
because I don't know how many I need at compile time. Inside each
TemplateColumn, I set ItemTemplate to a class derived from ITemplate. There,
I add a couple of TextBoxes inside Itemplate.InstantiateIn() method.

It seems InstantiateIn() method executes only if I do .DataSource and
..DataBind() on my DataGrid. However, I don't want to rebind the date on
postbacks because it's not necessary. I understand that as long as I
reconstruct my controls, the ViewState data will be automatically restored.
This works well on the columns I define inside aspx.

Is there a way to make InstantiateIn() execute or should I rebuild my
columns and their controls in some other method?
Here's my code:

private void Page_Load(object sender, System.EventArgs e)

{

DataTable dtPeriods = dsPeriods.Tables["Periods"];

foreach (DataRow row in dtPeriods.Rows)

{


PeriodColumn periodColumn = new
PeriodColumn(Convert.ToInt32(row["Period"]));

dgForecast.Columns.Add(periodColumn);

}

if (!IsPostBack)

{ dgForecast.DataSource = ds;

dgForecast.DataBind();

}

}

class PeriodColumn : TemplateColumn

{

public PeriodColumn(int periodNo)

{

this.periodNo = periodNo;

HeaderText = periodNo.ToString();

this.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;

ItemTemplate = new PeriodItemTemplate(periodNo);

}


private int periodNo;

}

class PeriodItemTemplate : ITemplate

{

public PeriodItemTemplate(int periodNo)

{ this.periodNo = periodNo;

}

#region ITemplate Members

public void InstantiateIn(Control container)

{

tbCost = new TextBox();

tbCost.Columns = 10;

TextBox tbRevenue = new TextBox();

tbRevenue.ID = "tbRevenue_" + periodNo;

tbRevenue.Columns = 10;

LiteralControl lcCost = new LiteralControl("Cost: ");

LiteralControl lcRevenue = new LiteralControl("Rev: ");

LiteralControl lcSeparator = new LiteralControl("<br>");

container.Controls.Add(lcCost);

container.Controls.Add(tbCost);

container.Controls.Add(lcSeparator);

container.Controls.Add(lcRevenue);

container.Controls.Add(tbRevenue);

}

#endregion



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can i execute aspx file in my asp pag with server.execute method(sorry) Savas Ates ASP General 1 08-17-2004 04:52 PM
execute window.open without a button pressed? cgia ASP .Net 2 04-02-2004 10:50 PM
execute the statements inside if statement without testing the if expression? Matt Java 3 03-01-2004 08:57 PM
Execute server code without complete page refresh (XMLHTTP) Matt ASP .Net 3 01-14-2004 09:50 PM
How must you do to execute PDM without influencing to active PIX? john Cisco 2 12-11-2003 02:37 AM



Advertisments