Solved

Repeater Control - generate template for this repeater dynamically.

Posted on 2009-05-20
4
419 Views
Last Modified: 2012-05-07
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.

0
Comment
Question by:bibmed2
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:GuitarRich
Comment Utility
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

0
 
LVL 1

Author Comment

by:bibmed2
Comment Utility
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 ?
0
 
LVL 12

Accepted Solution

by:
GuitarRich earned 500 total points
Comment Utility
like this:
Table tbl = new Table();

// Set the table options

TableRow row = new TableRow();

TableCell cell = new TableCell();
 
 

CheckBoxList list = new CheckBoxList();

list.Items.Add("add items here");

cell.Controls.Add(list);
 

row.Cells.Add(cell);
 

// Cary on building the table.

tbl.Rows.Add(row);

placeHolder.Controls.Add(tbl);

Open in new window

0
 
LVL 1

Author Comment

by:bibmed2
Comment Utility
Thanks for help :)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now