2013-01-23 91 views
0

我正在使用telerik:EditGridColumn。我需要做的是隱藏編輯圖像,如果列爲空或沒有評論。GridEditColumn上特定行的隱藏列

我所擁有的是GridEditcolumn和一些包含註釋的行。 如果註釋具有空值,editbutton將會隱藏。

這裏是我的代碼(aspx.cs)

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
     if (e.Item is GridDataItem) 
     { 
      GridDataItem item = e.Item as GridDataItem; 
      string strComments = (item["Comments"].FindControl("txtComments") as TextBox).Text; 
      if (strComments == null) 
      { 
       item["btnEdit"].CssClass = "RemoveEdit"; 
      } 
     } 
    } 

<style type="text/css"> 
     .RemoveEdit 
     { 
      display: none !important; 
     } 
    </style> 

的ASPX

<telerik:GridEditCommandColumn HeaderStyle-Width="25px" 
     EditImageUrl="../images/Edit.jpg" UniqueName="Edit" 
     ButtonType="ImageButton" ItemStyle-HorizontalAlign="Right"> 
</telerik:GridEditCommandColumn> 

<telerik:GridTemplateColumn HeaderText="Comments" 
    HeaderStyle-Width="400px" DataField="Comments" UniqueName="Comments" 
    HeaderStyle-CssClass="tblHeaderNoBorder"> 
    <ItemTemplate> 
     <asp:Label runat="server" ID="lblComments" Text='<%# Eval("Comments") %>' /> 
    </ItemTemplate> 
    <EditItemTemplate> 
     <asp:TextBox ID="txtComments" runat="server" Height="40px" 
       Width="100%" TextMode="MultiLine" 
       Enabled="true" Text='<%# Eval("Comments") %>'> 
     </asp:TextBox>    
    </EditItemTemplate> 
</telerik:GridTemplateColumn> 

回答

1

試試這個。

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
     { 
     if (e.Item is GridDataItem) 
     { 
      GridDataItem item = (GridDataItem)e.Item; 
      Label txtProcessStatus = e.Item.FindControl("ProcessStatusLabel") as Label; 
      if (txtProcessStatus.Text != "98") //your condition 
      { 
      ImageButton img = (ImageButton)item["EditCommandColumn"].Controls[0]; //Accessing EditCommandColumn 
      img.Visible = false; 
      }     
     }