Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Repeater ITemplate all in one table

Reply
Thread Tools

Repeater ITemplate all in one table

 
 
Matheson
Guest
Posts: n/a
 
      10-29-2003
I'm currently using classes implementing the ITemplate interface to
format the display of data that is bound to databound objects. I
started out using the DataList, but soon found that the datalist
performs some initial formatting for you. Specifically, it
automatically puts any bound data into a table row and table cell for
you (<tr><td>[my bound data column1]</td></tr>).

That's great, but what if you want to add another column and have it
align with the rest of the data? (<tr><td>[my bound data
column1]</td><td>[my bound data column2]</td></tr>)

So I'm trying to use the Repeater instead. It has no automatic
formatting. The end result I'm looking for is to be able to
dynamically decide which ITemplate to load for formatting the data and
then have all that data presented in one html table. I've seen
examples that accomplish this by using the ITemplate to manipulate a
string of HTML, but this seems limited. How would you then be able to
bind events to controls you wanted to add to each row, like
LinkButtons and such?

The ITemplate I am currently working with is listed below. If anybody
sees anything silly or can point me in a different direction, I would
really appreciate it. Thanks.

using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace sane2
{
public class IssuesTemplate : ITemplate
{
ListItemType templateType;

int count=0;
Table thisTable = new Table();

public void InstantiateIn(System.Web.UI.Control container){
thisTable.BorderWidth = 4;
thisTable.GridLines = GridLines.Both;
TableRow TR;
TableCell TD;

Label myLabel = new Label();

switch(templateType){
case ListItemType.Header:
TR = new TableRow();
TD = new TableCell();
TD.Text = "Header Text";
TR.Cells.Add(TD);
thisTable.Rows.Add(TR);
break;

case ListItemType.Item:
myLabel = new Label();
myLabel.Text = count.ToString();
myLabel.DataBinding += new EventHandler(myLabel_DataBinding);

TR = new TableRow();
TD = new TableCell();
TD.Controls.Add(myLabel);
TR.Cells.Add(TD);
thisTable.Rows.Add(TR);
break;

case ListItemType.Footer:
Label myLabel2 = new Label();
myLabel2.Text = "Footer Text";

TR = new TableRow();
TD = new TableCell();
TD.Controls.Add(myLabel2);
TR.Cells.Add(TD);
thisTable.Rows.Add(TR);

break;
}
container.Controls.Add(thisTable);
count++;
//container.Controls.Add(myLabel);
}

private void myLabel_DataBinding(object sender, System.EventArgs e)
{
Label myControl = (Label) sender;
RepeaterItem container = (RepeaterItem) myControl.NamingContainer;


myControl.Text = "<br>[" + DataBinder.Eval(container.DataItem,
"IssueID") + "]";
}

public IssuesTemplate(ListItemType type)
{
templateType = type;
}
}
}
 
Reply With Quote
 
 
 
 
MSFT
Guest
Posts: n/a
 
      10-30-2003
Hi Matheson,

How did you use the class IssuesTemplate in a DataList/Repeater control,
set it to ItemTemplate with code? To bind events to controls, I have seen
you bound databinding for the label control, is this not what you what?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
 
 
 
Matheson
Guest
Posts: n/a
 
      10-31-2003
This is in the pageLoad event (myDV is a populated Dataiew):

Repeater myR = new Repeater();
myR.DataSource = myDV;
myR.HeaderTemplate = new IssuesTemplate(ListItemType.Header);
myR.ItemTemplate = new IssuesTemplate(ListItemType.Item);
myR.FooterTemplate = new IssuesTemplate(ListItemType.Footer);
myR.DataBind();
Page.Controls.Add(myR);



http://www.velocityreviews.com/forums/(E-Mail Removed) (MSFT) wrote in message news:<(E-Mail Removed)>...
> Hi Matheson,
>
> How did you use the class IssuesTemplate in a DataList/Repeater control,
> set it to ItemTemplate with code? To bind events to controls, I have seen
> you bound databinding for the label control, is this not what you what?
>
> Luke
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)

 
Reply With Quote
 
MSFT
Guest
Posts: n/a
 
      10-31-2003
Hi Matheson,

To bind events to controls in the Repeater, I think you may add some code
in its ItemDataBound event, In this method, you can get each control in the
particualr row by:

e.Item.FindControl("ControlName")

And then use Addhandler to bind the control's event to any method you like.


Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie:Access custom Itemplate(not datagrid/repeater/datalist) control values on postback Luhar Powell via .NET 247 ASP .Net Building Controls 0 04-01-2005 04:59 PM
Newbie:Access custom Itemplate(not datagrid/repeater/datalist) control values on postback Luhar Powell via .NET 247 ASP .Net 0 04-01-2005 04:58 PM
Newbie:Access custom Itemplate(not datagrid/repeater/datalist) control values on postback Luhar Powell via .NET 247 ASP .Net Web Controls 0 04-01-2005 04:56 PM
DropDownList / <select> value not setting in Itemplate cosine... zero ASP .Net 0 06-11-2004 06:52 PM
Itemplate not accepting postback in data-bound templated control cosine... zero ASP .Net 0 06-09-2004 06:49 PM



Advertisments