Hello All:
I have a Datalist where each row has TextBoxes and Dropdowns that are
created dynamically. The code renders correctly and is very similar to this
sample I found
void rptFields_ItemD ataBound(object sender, RepeaterItemEve ntArgs e)
{
if (e.Item.ItemTyp e != ListItemType.It em && e.Item.ItemType
!= ListItemType.Al ternatingItem)
return;
DataRow dr = ((DataRowView)e .Item.DataItem) .Row;
PlaceHolder pl = (PlaceHolder)e. Item.FindContro l("plControl" );
switch (dr["DataType"].ToString().ToL ower())
{
case "string":
TextBox txt = new TextBox();
txt.ID = "txtField" + dr["pkParamete rID"].ToString();
pl.Controls.Add (txt);
break;
case "tf":
CheckBox chk = new CheckBox();
chk.ID = "chkField" + dr["pkParamete rID"].ToString();
pl.Controls.Add (chk);
break;
}
When I call the DataList ItemCommand Event, I am unable to reference the
dropdown list or textbox by using the FindControl Method even if I hardcode
the ControlId as a test.
How can I get the selected value or text of the control
Any help appreciated
Thanks
Stuart
I have a Datalist where each row has TextBoxes and Dropdowns that are
created dynamically. The code renders correctly and is very similar to this
sample I found
void rptFields_ItemD ataBound(object sender, RepeaterItemEve ntArgs e)
{
if (e.Item.ItemTyp e != ListItemType.It em && e.Item.ItemType
!= ListItemType.Al ternatingItem)
return;
DataRow dr = ((DataRowView)e .Item.DataItem) .Row;
PlaceHolder pl = (PlaceHolder)e. Item.FindContro l("plControl" );
switch (dr["DataType"].ToString().ToL ower())
{
case "string":
TextBox txt = new TextBox();
txt.ID = "txtField" + dr["pkParamete rID"].ToString();
pl.Controls.Add (txt);
break;
case "tf":
CheckBox chk = new CheckBox();
chk.ID = "chkField" + dr["pkParamete rID"].ToString();
pl.Controls.Add (chk);
break;
}
When I call the DataList ItemCommand Event, I am unable to reference the
dropdown list or textbox by using the FindControl Method even if I hardcode
the ControlId as a test.
How can I get the selected value or text of the control
Any help appreciated
Thanks
Stuart
Comment