I have created a number of RadioButton controls during the OnItemDataBound
event of a datagrid control.
..aspx file:
<asp:datagrid id="dgProductOp tions" runat="server"
AutoGenerateCol umns="False" OnItemDataBound ="LoadChildReco rds" Width="100%">
codebehind:
public void LoadChildRecord s(object Sender, DataGridItemEve ntArgs e){
if(e.Item.ItemT ype == ListItemType.Al ternatingItem || e.Item.ItemType ==
ListItemType.It em){
DataList dlPrintFinish = (DataList)e.Ite m.FindControl(" dlPrintFinish") ;
DataView dvOptions =
((DataRowView)e .Item.DataItem) .CreateChildVie w("ProductOptio ns");
System.Web.UI.H tmlControls.Htm lTable tbl = new HtmlTable();
tbl.Border = 0;
tbl.CellPadding = 0;
tbl.CellSpacing = 0;
tbl.Width = "100%";
for(int i=0; i<dvOptions.Cou nt; i++){
HtmlTableRow tr = new HtmlTableRow();
HtmlTableCell td = new HtmlTableCell() ;
HtmlInputRadioB utton rad = new HtmlInputRadioB utton();
rad.ID = "radFinish" ;
rad.Name = "radFinish" ;
rad.Value = dvOptions[i]["ProductSKU "].ToString();
rad.EnableViewS tate = true;
Label lblFinish = new Label();
lblFinish.Text = dvOptions[i]["FinishDescript ion"].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(dv Options[i]["MSRP"].ToString()).To String("C");
td2.Controls.Ad d(lbl);
tr.Cells.Add(td 2);
tbl.Rows.Add(tr );
}
phdPrintFinish = (PlaceHolder)e. Item.FindContro l("phdPrintFini sh");
phdPrintFinish. Controls.Add(tb l);
}
}
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?
event of a datagrid control.
..aspx file:
<asp:datagrid id="dgProductOp tions" runat="server"
AutoGenerateCol umns="False" OnItemDataBound ="LoadChildReco rds" Width="100%">
codebehind:
public void LoadChildRecord s(object Sender, DataGridItemEve ntArgs e){
if(e.Item.ItemT ype == ListItemType.Al ternatingItem || e.Item.ItemType ==
ListItemType.It em){
DataList dlPrintFinish = (DataList)e.Ite m.FindControl(" dlPrintFinish") ;
DataView dvOptions =
((DataRowView)e .Item.DataItem) .CreateChildVie w("ProductOptio ns");
System.Web.UI.H tmlControls.Htm lTable tbl = new HtmlTable();
tbl.Border = 0;
tbl.CellPadding = 0;
tbl.CellSpacing = 0;
tbl.Width = "100%";
for(int i=0; i<dvOptions.Cou nt; i++){
HtmlTableRow tr = new HtmlTableRow();
HtmlTableCell td = new HtmlTableCell() ;
HtmlInputRadioB utton rad = new HtmlInputRadioB utton();
rad.ID = "radFinish" ;
rad.Name = "radFinish" ;
rad.Value = dvOptions[i]["ProductSKU "].ToString();
rad.EnableViewS tate = true;
Label lblFinish = new Label();
lblFinish.Text = dvOptions[i]["FinishDescript ion"].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(dv Options[i]["MSRP"].ToString()).To String("C");
td2.Controls.Ad d(lbl);
tr.Cells.Add(td 2);
tbl.Rows.Add(tr );
}
phdPrintFinish = (PlaceHolder)e. Item.FindContro l("phdPrintFini sh");
phdPrintFinish. Controls.Add(tb l);
}
}
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?
Comment