2017-11-06 17 views
2

데이터 그리드가 있으며 ItemTamplate가 있고 거기에 2 개의 레이블이 있으며 둘 다 데이터가 들어 있습니다.Datagrid에서 ItemTamplate 레이블의 값 확인

나는 전체의 GridView를 통해 루프 수 및 라벨 작업 Keyboarding 포함 된 경우보고 싶어하고 fails 또는 Pass의 제품에 Incomplete에서 두 번째 레이블의 값을 변경 않는 경우.

다음은 코드입니다.

<asp:datagrid id="dgData" runat="server" Width="658px" CellPadding="2" PageSize="2" DataKeyField="ID" 
      AutoGenerateColumns="False" ShowFooter="True" BorderColor="AliceBlue" OnItemDataBound="dgData_ItemDataBound"> 
    <SelectedItemStyle ForeColor="HighlightText" BackColor="Highlight"></SelectedItemStyle> 
    <AlternatingItemStyle BackColor="WhiteSmoke"></AlternatingItemStyle> 
    <HeaderStyle Font-Bold="True" BackColor="AliceBlue"></HeaderStyle> 
    <FooterStyle Font-Bold="True" BackColor="AliceBlue"></FooterStyle> 
    <Columns> 
    <asp:BoundColumn DataField="ID" Visible="False"></asp:BoundColumn> 
    <asp:BoundColumn DataField="Name" HeaderText="" ItemStyle-VerticalAlign="Top"></asp:BoundColumn> 
    <asp:TemplateColumn HeaderText="Term 1" ItemStyle-Wrap="True"> 
     <ItemTemplate> 
     <asp:label BorderStyle=None Visible='<%# ReverseBool(Convert.ToBoolean(DataBinder.Eval(Container, "DataItem.IsCompleteOrNot"))) %>' runat="server" ID="edit_Score" Text='<%# DataBinder.Eval(Container, "DataItem.Score") %>'> 
     </asp:label> 
     <asp:label BorderStyle=None Text='<%# GetCompleteIncomplete(Convert.ToInt32(DataBinder.Eval(Container, "DataItem.Score"))) %>' Visible='<%# DataBinder.Eval(Container, "DataItem.IsCompleteOrNot") %>' id="txtIsComplete" runat="server"> 
     </asp:label> 
     </ItemTemplate> 
    </asp:TemplateColumn> 

    </Columns> 
</asp:datagrid> 

이제 C#을 서버 GetCompleteIncomplete에 대한 통화는 한 경우에 보이는 C#에서 방법의 그 0 완전한에서 경우 전체 :

protected string GetCompleteIncomplete(int iScore) 
{ 
    if (iScore == 0) 
    { 
     return "Incomplete"; 
    } 

    return "Complete"; 
} 

이쪽을 반환 레이블에 값을 지정하면 다음과 같이 표시됩니다. This is how it looks like

는하지만/그 불완전을 변경/실패 첫 번째 레이블이 Keyboarding 다른 라인이 불완전하거나 전체 머물 수있는 경우에만 통과하기 위해 경쟁하고 싶다. 당신하여 ItemDataBound 이벤트에서 코드 아래

답변

1

시도 :

if ((e.Item.ItemType == ListItemType.Item) || 
        (e.Item.ItemType == ListItemType.AlternatingItem)) 
{ 
    Label edit_Score = (Label)e.Item.FindControl("edit_Score"); 
    Label txtIsComplete = (Label)e.Item.FindControl("txtIsComplete"); 

    if (edit_Score.Text == "Keyboarding") 
    { 
     if (txtIsComplete.Text == "Complete") 
     { 
      txtIsComplete.Text = "Pass"; 
     } 
     else if(txtIsComplete.Text == "InComplete") 
     { 
      txtIsComplete.Text = "Fail"; 
     } 
    } 

}