473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Initialize dynamic controls on postback

I have created a number of RadioButton controls during the OnItemDataBound
event of a datagrid control.

..aspx file:
<asp:datagrid id="dgProductOptions" runat="server"
AutoGenerateColumns="False" OnItemDataBound="LoadChildRecords" Width="100%">
codebehind:
public void LoadChildRecords(object Sender, DataGridItemEventArgs e){
if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType ==
ListItemType.Item){
DataList dlPrintFinish = (DataList)e.Item.FindControl("dlPrintFinish");
DataView dvOptions =
((DataRowView)e.Item.DataItem).CreateChildView("Pr oductOptions");
System.Web.UI.HtmlControls.HtmlTable tbl = new HtmlTable();
tbl.Border = 0;
tbl.CellPadding = 0;
tbl.CellSpacing = 0;
tbl.Width = "100%";
for(int i=0; i<dvOptions.Count; i++){
HtmlTableRow tr = new HtmlTableRow();
HtmlTableCell td = new HtmlTableCell();
HtmlInputRadioButton rad = new HtmlInputRadioButton();
rad.ID = "radFinish";
rad.Name = "radFinish";
rad.Value = dvOptions[i]["ProductSKU"].ToString();
rad.EnableViewState = true;
Label lblFinish = new Label();
lblFinish.Text = dvOptions[i]["FinishDescription"].ToString();
if(i==0){
rad.Checked = true;
}
td.Controls.Add(rad);
td.Controls.Add(lblFinish);
tr.Cells.Add(td);
HtmlTableCell td2 = new HtmlTableCell();
Label lbl = new Label();
lbl.Text = Double.Parse(dvOptions[i]["MSRP"].ToString()).ToString("C");
td2.Controls.Add(lbl);
tr.Cells.Add(td2);
tbl.Rows.Add(tr);
}
phdPrintFinish = (PlaceHolder)e.Item.FindControl("phdPrintFinish");
phdPrintFinish.Controls.Add(tbl);
}
}
I realize that I need to recreate these controls during the OnLoad event,
but I'm not clear how to do this. The number of rows and the number of
RadioButton controls per row are both unknown until I have the data. How can
I recreate these controls on postback in order to read their values?

Nov 17 '05 #1
1 4486
That is a problem
I had to re-create my controls by getting my data again from the database or
from a persisted DataSet
I hape you find a better answer
"Mark Miller" <no**********@waveshift.com> wrote in message
news:eu****************@TK2MSFTNGP12.phx.gbl...
I have created a number of RadioButton controls during the OnItemDataBound
event of a datagrid control.

.aspx file:
<asp:datagrid id="dgProductOptions" runat="server"
AutoGenerateColumns="False" OnItemDataBound="LoadChildRecords" Width="100%">

codebehind:
public void LoadChildRecords(object Sender, DataGridItemEventArgs e){
if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType ==
ListItemType.Item){
DataList dlPrintFinish = (DataList)e.Item.FindControl("dlPrintFinish");
DataView dvOptions =
((DataRowView)e.Item.DataItem).CreateChildView("Pr oductOptions");
System.Web.UI.HtmlControls.HtmlTable tbl = new HtmlTable();
tbl.Border = 0;
tbl.CellPadding = 0;
tbl.CellSpacing = 0;
tbl.Width = "100%";
for(int i=0; i<dvOptions.Count; i++){
HtmlTableRow tr = new HtmlTableRow();
HtmlTableCell td = new HtmlTableCell();
HtmlInputRadioButton rad = new HtmlInputRadioButton();
rad.ID = "radFinish";
rad.Name = "radFinish";
rad.Value = dvOptions[i]["ProductSKU"].ToString();
rad.EnableViewState = true;
Label lblFinish = new Label();
lblFinish.Text = dvOptions[i]["FinishDescription"].ToString();
if(i==0){
rad.Checked = true;
}
td.Controls.Add(rad);
td.Controls.Add(lblFinish);
tr.Cells.Add(td);
HtmlTableCell td2 = new HtmlTableCell();
Label lbl = new Label();
lbl.Text = Double.Parse(dvOptions[i]["MSRP"].ToString()).ToString("C");
td2.Controls.Add(lbl);
tr.Cells.Add(td2);
tbl.Rows.Add(tr);
}
phdPrintFinish = (PlaceHolder)e.Item.FindControl("phdPrintFinish");
phdPrintFinish.Controls.Add(tbl);
}
}
I realize that I need to recreate these controls during the OnLoad event,
but I'm not clear how to do this. The number of rows and the number of
RadioButton controls per row are both unknown until I have the data. How can I recreate these controls on postback in order to read their values?

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Williamson | last post by:
When a ASPX page is created with dynamic controls based on what the user is doing the programmer must recreate the dynamic controls again on PostBack in the Page_Load so that it's events are wired...
3
by: Tyler Carver | last post by:
I am trying to use some dynamic controls that are built and then added to tables. The problem that I am having is the timing of when I can populate the controls and have the state remain after a...
5
by: PCH | last post by:
I have an c# asp.net (.net 1.1) web page, viewstate on. The problem I am having is on the button click postback to update. Heres the situation: I have an asp table that has 1 header row. ...
1
by: dx | last post by:
I'm extremely frustrated with ASP.NET...again! To me this should be as simple as setting oCheckBox.Checked = True.. yet for some reason it isn't. I have a user control (ascx) that that has a...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
2
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
4
by: =?Utf-8?B?RHlsYW5TbWl0aA==?= | last post by:
I have a WebForm where I'm dynamically creating some controls and I'm having difficulty understanding how the state is being persisted and how to work with it. I've created a simplified example...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.