2013-06-30 2 views
0

Я пытаюсь изменить ItemTemplate asp: TemplateField, так что если свойство waitingFor находится ниже 120, отображается индикатор выполнения, если значение выше текста Not Applicable is показать.GridView с шаблоном, которое изменяется в зависимости от свойства

Как бы вы сделать что-то похожее на то, что я пытался ниже

     <asp:TemplateField HeaderText="Time" HeaderStyle-CssClass="table-header-repeat line-left" 
                SortExpression="WaitingFor"> 
                if(Eval("WaitingFor")<120){ 
                <ItemTemplate> 
                 <span id="progressBar<%# Eval("OrderId") %>sec" style="color: #006600; font-weight: bold;"> 
                  <%# Eval("WaitingFor") %> 
                  s</span> 
                 <br /> 
                 <span id="progressBar<%# Eval("OrderId") %>" ordernr="<%# Eval("OrderId") %>" class="progressBar" 
                  waitingfor="<%# Eval("WaitingFor") %>">[ Loading Progress Bar ]</span> 
                </ItemTemplate> 
                }else{ 
                <ItemTemplate> 
                 Not applicable 
                </ItemTemplate> 
                } 
                <HeaderStyle CssClass="table-header-repeat line-left" /> 
                <ItemStyle Width="150px" /> 
               </asp:TemplateField> 

ответ

0

Почему бы вам не сделать только один <ItemTemplate>, который имеет серверные элементы управления внутри него, а затем вы можете показать/скрыть те, которые делают или не отвечают следующим условиям:

Markup: 
<asp:TemplateField HeaderText="Time" HeaderStyle-CssClass="table-header-repeat line-left" SortExpression="WaitingFor"> 
    <ItemTemplate> 
     <asp:Label id="Seconds" runat="server" style="color: #006600; font-weight: bold;"></asp:Label> 
     <br /> 
     <asp:Label id="ProgressBar" ruant="server" data-ordernr="<%# Eval("OrderId") %>" CssClass="progressBar" data-waitingfor="<%# Eval("WaitingFor") %>">[ Loading Progress Bar ]</asp:Label> 
     <asp:Label id="NotApplicable" runat="server" Visible="False">Not applicable</asp:Label> 
    </ItemTemplate>            
    <HeaderStyle CssClass="table-header-repeat line-left" /> 
    <ItemStyle Width="150px" /> 
</asp:TemplateField> 

Code-behind: 
protected void GridView_People_RowDataBound(object sender, GridViewRowEventArgs e) 
{    
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     // Cast the e.Row object to type the GridView was bound to 


     // Setup conditional logic here for what you want to test (WaitingFor value less than 120 seconds) 

     // In else logic, hide the Seconds label, the ProgressBar label and show the NotApplicable label, like this: 
     Label secondsLabel = e.Row.FindControl("Seconds") as Label; 

     // Check for null before trying to use the control, like this: 
     if(secondsLabel != null) 
     { 
      // Hide the label 
      secondsLabel.Visible = false; 
     } 

     // Rinse and repeat for other controls that you want to show/hide 
    } 
} 
Смежные вопросы