隐藏GridEditColumn上特定行的列

时间:2013-01-23 03:32:50

标签: c# asp.net telerik radgrid

我正在使用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>

for 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 个答案:

答案 0 :(得分: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;
           }                  
       }