Can I Do This

W

Wayne Wengert

I have an aspx page that includes a bound data repeater. In the ItemTemplate
section I display each row from the datasource as a set of fields in a row
in a table. e.g.:

<tr>
<td align="center"><%# DataBinder.Eval(Container,"DataItem.Group") %></td>
<td align="center"><%# DataBinder.Eval(Container,"DataItem.Count") %></td>
.....
</tr>

I want to insert a special output row whenever the value of "DataItem.Group"
changes. That extra row will span all columns and display the value of
"DataItem.Group" . I tried inserting a row with the layout I want for that
header row using the code below:

<tr id=newclass bgcolor="#ffff66" height=0>
<td height=0 colspan=8>New Class</td>
</tr>

I thought I could then catch the change in the DataItem.Group in the Item
Databind Event and change the rowheight to something like 12 and fill in the
correct text.

It turns out that even though the height is set to 0 that row displays?

Any suggestions on how to accomplish this?

Wayne
 
E

Eliyahu Goldin

Wayne,

Add runat="server" to the <tr id=newclass ... > and in ItemDataBound event
set property Visible to false. The row won't render to the client at all.

Eliyahu
 
W

Wayne Wengert

Eliyahu;

Thanks for the response but the <tr> and <td> elements do not have a
"visible" property?

Wayne
 
W

Wayne Wengert

Eliyahu;

I must be missing something here. I added the runat="server", switched back
to Design View and back to the HTML view but I don't see any change in the
<tr> tag nor is there a "Visible" property. When you say that it changes to
a HTMLTableRow, where does that appear? That segment of my code is as
follows:

<tr id="newclass" bgcolor="#ffff66" runat="server" height="0">
<td id="newclasscol" runat="server" colspan="8" align="center"
height="0">New Class</td>
</tr>

Wayne
 
E

Eliyahu Goldin

Wayne,

You are right. But when you add runat="server" your <tr> becomes
HtmlTableRow and <td> turns to HtmlTableCell. And they do have Visible.
Don't forget to switch to design view to get visual studio make changes to
the code-behind.

Eliyahu
 
E

Eliyahu Goldin

Wayne,

Sorry, I missed the point that you are doing this within ItemTemplate. You
still can set runat="server" for the <table>. Let the table build itself
with data binding and then, at the end, in PreRender event, loop through the
table, find the rows you want to hide and set for them Visible=false. You
can do it in either server script or code behind.

Eliyahu
 
S

Sayed Hashimi

Wayne,

You can try this:

1) Add another row to your template, but make the row invisible.
2) Handle the item bound event to track the group. You can do this by
maintaining a class member variable.
3) When the Group changes, then make the invisible row visible.

Basically, you add an additional row to every row of the data source,
but only show the additional row when the group changes.


sayed
 
W

Wayne Wengert

Sayed;

The problem is that there is no "visible" property on the standard <tr>

Wayne
 
E

Eliyahu Goldin

Wayne,

You can make any html invisible by setting css rule display:none.

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top