c#
  • asp.net
  • 2013-08-30 38 views -2 likes 
    -2

    聽到我發佈了我的網格視圖。 如何使網格視圖標籤可見false

       <Columns> 
            <asp:TemplateField HeaderText="Item"> 
              <ItemTemplate> 
               <p> <asp:Label ID="lblproductname" display="Dynamic" runat="server" Text='<%# Bind("productname") %>'></asp:Label></p> 
               <p><asp:Label ID="lblProductWeight" display="Dynamic" runat="server" Text='<%# Bind("groupvalue") %>'></asp:Label></p> 
               <p> <asp:Label ID="lblProductType" display="Dynamic" runat="server" Text='<%# Bind("groupname") %>'></asp:Label></p> 
              </ItemTemplate> 
              <HeaderStyle HorizontalAlign="Left" /> 
              <ItemStyle HorizontalAlign="Left" /> 
             </asp:TemplateField> 
            <asp:BoundField DataField="Quantity" HeaderText="Qty"> 
             <HeaderStyle HorizontalAlign="Left" /> 
            </asp:BoundField> 
            <asp:BoundField DataField="Price" HeaderText="Price"> 
             <HeaderStyle HorizontalAlign="Left" /> 
            </asp:BoundField> 
            <asp:BoundField DataField="SubTotal" HeaderText="Sub Total"> 
               <HeaderStyle HorizontalAlign="Left" /> 
              </asp:BoundField> 
           </Columns> 
           <FooterStyle CssClass="datatable" /> 
          </asp:GridView> 
    

    因此如何使標貼的可見假的ItemTemplate programaticaly在XYZ方法

    +0

    我不是當然,如果這樣s是正確的,所以不想編輯問題,但我相信問題是:「我怎樣才能在'ItemTemplate'中更改三個標籤的可見性? – Sayse

    回答

    3

    在Rowcommand你可以隱藏或網格顯示,例如項目模板:

    void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e) 
        { 
    
        if(e.Row.RowType == DataControlRowType.DataRow) 
        { 
         //Your Condition 
         Label lblproductname = (Label)e.Row.FindControl("lblproductname") 
         If(a > B) 
         lblproductname.Visible = true; 
         //Others Lables 
         .... 
    
        } 
    
        } 
    

    我希望有所幫助。

    0
    protected void OnRowCreated(object sender, GridViewRowEventArgs e) 
    { 
         e.Row.Cells[columnIndex].Visible = false; 
    } 
    

    唯一的解決方法我可以建議是給在aspx頁的HeaderText,然後找到使用。

    protected void xyz() 
    { 
        ((DataControlField)youGridView.Columns 
          .Cast<DataControlField>() 
          .Where(fld => fld.HeaderText == "your header text") 
          .SingleOrDefault()).Visible = false; 
    } 
    
    0

    我相信您的問題在這裏得到解答:

    How to find control in TemplateField of GridView?

    從答案複製:

    foreach(GridViewRow row in GridView1.Rows) { 
        if(row.RowType == DataControlRowType.DataRow) { 
         Label myLabel = row.FindControl("myLabelID") as Label; 
         myLabel.Visible = false; 
        } 
    } 
    

    從RowDataBoundEvent:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
        if(e.Row.RowType == DataControlRowType.DataRow) 
        { 
         Label myLabel = e.Row.FindControl("myLabelID") as Label; 
         myLabel.Visible = false; 
        } 
    } 
    
    相關問題