Conditional Delete

3 posts, 1 answers
  1. RB
    RB avatar
    126 posts
    Member since:
    Dec 2013

    Posted 21 Apr 2014 Link to this post

    I have a boolean ShowDelete. If it is true, Delete button in the grid columns should be visible. Not otherwise. How can I achieve this?
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Apr 2014 in reply to RB Link to this post

    Hi RB,

    Please have a look into the sample code snippet for hiding/showing the delete button of RadGrid based on the Boolean value.

    ASPX:
    <telerik:RadGrid ID="radgrdOrders" runat="server" DataSourceID="SqlDataSource1" AutoGenerateDeleteColumn="true" AutoGenerateColumns="false" OnItemDataBound="radgrdOrders_ItemDataBound">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="OrderID" UniqueName="OrderID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="CustomerID" UniqueName="CustomerID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Status" UniqueName="Status">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    C#:
    protected void radgrdOrders_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        foreach (GridDataItem dataItem in radgrdOrders.Items)
        {
            LinkButton deleteBtn = (LinkButton)dataItem.FindControl("AutoGeneratedDeleteButton");
            string statusCheck = dataItem["Status"].Text;
            if (statusCheck == "False")
                deleteBtn.Visible = false;
        }
    }

    Thanks,
    Princy.
  3. RB
    RB avatar
    126 posts
    Member since:
    Dec 2013

    Posted 22 Apr 2014 Link to this post

    Thanks
Back to Top