0

我正在使用 Telerik:EditGridColumn。如果该列为空或没有评论,我需要做的是隐藏编辑图像。

我所拥有的是 GridEditcolumn 和一些包含评论的行。如果评论具有空值,则编辑按钮将隐藏。

这是我的代码(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>
4

1 回答 1

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;
           }                  
       }
于 2013-07-24T06:31:39.320 回答