Reputation: 303
I'm using telerik:EditGridColumn. What I need to do is to hide the edit image if the column is null or no comments.
what i have is GridEditcolumn and some rows that contains comment. if the comments has null value the editbutton will just hide.
here is my code (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>
Upvotes: 0
Views: 2835
Reputation: 800
Try this.
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;
}
}
Upvotes: 1