Link to home
Start Free TrialLog in
Avatar of bibmed2
bibmed2Flag for Poland

asked on

Repeater Control - generate template for this repeater dynamically.

I am using a Repeater Control . Now , I want to generate all Template for this Repeater Dynamically.

This is what I want accomplish (schema):

foreach (RepeaterItem repeatItem in Repeater1.Items)
{
 // Add ItemTemplate DataItems Dynamically
 if (.........)
 {
   //template1
   //ASP Table object here NOT LiteralControl  as  new LiteralControl("<table>"); In header Template  
  }
elseif (.......)
  {
  //template2
  //ASP CheckBoxList
  }
}

I`d like to do it form code behind.

Avatar of GuitarRich
GuitarRich
Flag of United Kingdom of Great Britain and Northern Ireland image

To do that I'd put a LiteralControl or Panel in the item template and add the controls to it. But rather than loop, I would do this in the ItemDataBound event so that you had good access to the data too. So if you had a Panel in the item template you could do
	protected void repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
	{
		Panel placeHolder = (Panel)e.Item.FindControl("panel1");
		// Add ItemTemplate DataItems Dynamically
		if (true)
		{
			//template1
			//ASP Table object here NOT LiteralControl  as  new LiteralControl("<table>"); In header Template  
			Table tbl = new Table();
			// Set the table options
			TableRow row = new TableRow();
			TableCell cell = new TableCell();
			cell.Text = "some text";
			row.Cells.Add(cell);
 
			// Cary on building the table.
			tbl.Rows.Add(row);
			placeHolder.Controls.Add(tbl);
		}
		else if (false)
		{
			//template2
			//ASP CheckBoxList
			CheckBoxList list = new CheckBoxList();
			list.Items.Add("add items here");
			placeHolder.Controls.Add(list);
		}
	}

Open in new window

Avatar of bibmed2

ASKER

Thank you for response.

But how can I put one control into another for example:

ASP CheckBoxList into ASP Table in particular row and column ?
ASKER CERTIFIED SOLUTION
Avatar of GuitarRich
GuitarRich
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bibmed2

ASKER

Thanks for help :)