Solved

Repeater Control - generate template for this repeater dynamically.

Posted on 2009-05-20
4
423 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24430408
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
ID: 24430489
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
ID: 24430539
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
ID: 24430612
Thanks for help :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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