Solved

Repeater Control - generate template for this repeater dynamically.

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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 …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

17 Experts available now in Live!

Get 1:1 Help Now