Solved

Repeater Control - generate template for this repeater dynamically.

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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