[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Repeater Control - generate template for this repeater dynamically.

Posted on 2009-05-20
4
Medium Priority
?
428 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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

868 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