RE: If Then statement inside of repeater control

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Steven Cheng[MSFT] (v-schang_at_online.microsoft.com)
Date: 10/22/04


Date: Fri, 22 Oct 2004 08:27:05 GMT

Hi Sck10,

Thanks for your posting. As for the problem you mentioned, here are some of
my understandings:
1. The<% %> expression is only used in page(or UserControl, ascx) 's page
level template , but unable to be used in any asp.net web server control's
databinding template. We can only use <%# %> databinding expression to
bind value to asp.net server control's properties or template. For example:
<asp:TextBox ... Text="<% ...%>" ...> is not allowed,

we should use <asp:TextBox ... Text=<%# .. %> ..>
Also, the expression or code will be called when the TextBox (or its parent
container )'s DataBind method is called.

2. As for your problem, I think you should put the If ...else statement
logic into the <#% %> block . Forexample:

<ItemTemplate>

<%# GetHeader( Container.DataItem("Status") ) %>

 <tr>
  <td width="120"><%# Container.DataItem("Status") %></div></td>
  <td width="80"><%# Container.DataItem("StatusCount") %></div></td>
  <td width="80"><%# Container.DataItem("PercentTotal") %>%</div></td>
 </tr>

</ItemTemplate>

GetHeader( string) is a helper function defined in the codebehind class
which return the correct html depend on the input param. such as:

#must be protected or public so that we can call it in aspx page's inline
code
protected string GetHeader(string status)
{
    if(status== xxx)
     {
        return "<tr><td width=\"280\" colspan=\"3\"><hr
color=#0000FF></td></tr>";
     }else
     {
        return string.Empty;
     }
}

Hope helps. IF you have anything else unclear, please feel free to post
here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

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



Relevant Pages

  • RE: GridView with Password Field
    ... As for the TextBox in template field, if you use "Bind" expression and ... it automatically provide two-way databinding function. ... Are you using custom code to do the database updating(so that you need to ... manually get reference to the data in textbox)? ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Idea gathering, suggestions welcome
    ... I'm not sure I follow your comments about a user control. ... suggest a usercontrol as an ascx template. ... And as for using UserControl, I think it a good approach, you can add those ... template) and then apply databinding expression on their properties. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Ruby Jobs Site (#47)
    ... What follows is another basic solution using ActiveRecord only and CGI. ... Each template is a separate entry ... class Posting < ActiveRecord::Base ...
    (comp.lang.ruby)
  • RE: envelopes layout
    ... Based on my knowledge and further test, you could customize the envelope ... After customizing the template, you will notice all the contacts will ... This posting is provided "AS IS" with no warranties, ... | From: "Mark Stow" ...
    (microsoft.public.outlook.general)
  • Re: Seting a Constant (via code) when creating a new file based on a template
    ... Sorry for posting the same question twice. ... > I have a time sheet template. ... > to the date the time sheets need to be emailed. ...
    (microsoft.public.excel.programming)