DataList ItemCommand using Placeholder Ctrl

  • Thread starter Thread starter Stuart Shay
  • Start date Start date
S

Stuart Shay

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

http://www.codeguru.com/csharp/.net/net_asp/controls/article.php/c12495/

void rptFields_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType
!= ListItemType.AlternatingItem)
return;

DataRow dr = ((DataRowView)e.Item.DataItem).Row;
PlaceHolder pl = (PlaceHolder)e.Item.FindControl("plControl");
switch (dr["DataType"].ToString().ToLower())
{
case "string":
TextBox txt = new TextBox();
txt.ID = "txtField" + dr["pkParameterID"].ToString();
pl.Controls.Add(txt);
break;

case "tf":
CheckBox chk = new CheckBox();
chk.ID = "chkField" + dr["pkParameterID"].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
 
Back
Top