Solved

Repeater Control - generate template for this repeater dynamically.

Posted on 2009-05-20
4
421 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

18 Experts available now in Live!

Get 1:1 Help Now