This is a migrated thread and some comments may be shown as answers.

[Solved] Hidden item in ItemDataBound APPEAR in editmode

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sayid s Yoshi
Top achievements
Rank 1
Sayid s Yoshi asked on 03 Jul 2009, 09:34 AM
In my Grid, There is a column "status" and a command link button column "delete"
If "Status" = 0, I set the command button column item to Empty string "" in the ItemDataBound events.
This work properly and pretty good.

But when I edit the row in editform mode, the "delete" command APPEAR!! ... ...
How to handle this case?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Jul 2009, 10:14 AM
Hi Sayid S Yoshi,

If you are using EditMode="EditForms", then try the following code snippet to hide Delete button in the row if Status="0".

C#:
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridDataItem) 
    { 
        GridDataItem item = (GridDataItem)e.Item; 
        if (item["Status"].Text == "0"
        { 
            LinkButton lnk = (LinkButton)item.FindControl("btnDelete"); 
            lnk.Visible = false
        } 
    } 

Try the following code if you are using EditMode="InPlace".
C#:
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridDataItem && e.Item.IsInEditMode) 
    { 
        GridDataItem item = (GridDataItem)e.Item; 
        if ((item["Status"].Controls[0] as TextBox).Text == "0"
        { 
            LinkButton lnk = (LinkButton)item.FindControl("btnDelete"); 
            lnk.Visible = false
        } 
    } 
    if (e.Item is GridDataItem) 
    { 
        GridDataItem item = (GridDataItem)e.Item; 
        if (item["Status"].Text == "0"
        { 
            LinkButton lnk = (LinkButton)item.FindControl("btnDelete"); 
            lnk.Visible = false
        } 
    } 

And the ASPX is,
 
<Columns> 
    <telerik:GridTemplateColumn UniqueName="DeleteColumn"
        <ItemTemplate> 
            <asp:LinkButton runat="server" CommandName="Delete" Text="Delete" ID="btnDelete"></asp:LinkButton> 
        </ItemTemplate> 
    </telerik:GridTemplateColumn> 
    <telerik:GridBoundColumn DataField="Status" HeaderText="Status" SortExpression="Status" UniqueName="Status"
    </telerik:GridBoundColumn> 
        . . . 
</Columns> 

Feel free to share the comments,
Shinu.
Tags
Grid
Asked by
Sayid s Yoshi
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or