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

Disable a ASP-button based on columnvalues

2 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pascal
Top achievements
Rank 1
Pascal asked on 19 Feb 2013, 09:57 AM
<telerik:RadGrid ID="RadGridQuotes" runat="server" OnNeedDataSource="RadGridQuotes_NeedDataSource"
    PageSize="15" EnableAjax="True" OnItemDataBound ="RadGridQuotes_ItemDataBound" >
    <MasterTableView ShowFooter="true" DataKeyNames="ID">
        <Columns>
            <telerik:GridBoundColumn DataField="ID" HeaderText="ID" DataType="System.Int32" ItemStyle-Width="50" HeaderStyle-Width="50" />
            <telerik:GridBoundColumn DataField="Views" HeaderText="Views" DataType="System.Int32" ItemStyle-Width="40" HeaderStyle-Width="40" />
            <telerik:GridBoundColumn DataField="ClientID" HeaderText="ClientID" DataType="System.Int32" ItemStyle-Width="50" HeaderStyle-Width="50"  />
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" DataType="System.String" ItemStyle-Width="200" HeaderStyle-Width="200"/>
            <telerik:GridBoundColumn DataField="EmailAddress" HeaderText="EmailAddress" DataType="System.String" />
            <telerik:GridBoundColumn DataField="Sex" HeaderText="Sex" DataType="System.String" ItemStyle-Width="40" HeaderStyle-Width="40"/>
            <telerik:GridBoundColumn DataField="PhoneNumber" HeaderText="PhoneNumber" DataType="System.String" />
            <telerik:GridBoundColumn DataField="Inserted" HeaderText="Inserted" DataType="System.DateTime" DataFormatString="{0:dd-MM-yyyy}" />
            <telerik:GridBoundColumn DataField="Type" HeaderText="Type" DataType="System.String"  ItemStyle-Width="70" HeaderStyle-Width="70" />
            <telerik:GridCheckBoxColumn DataField="IsTransfer" UniqueName="IsTransfer" HeaderText="IsTransfer" DataType="System.Boolean"  ItemStyle-Width="70" HeaderStyle-Width="70" />
            <telerik:GridCheckBoxColumn DataField="IsOther" HeaderText="IsOther" DataType="System.Boolean"  ItemStyle-Width="70" HeaderStyle-Width="70" />
            <telerik:GridTemplateColumn AllowFiltering="false" HeaderStyle-Width="120" UniqueName="DownloadQuoteButton">
                <ItemTemplate>
                    <asp:Button ID="ButtonOpen" runat="server" CausesValidation="false" OnClick="ButtonOpen_OnClick"
                        CommandArgument='<%# DataBinder.Eval(Container.DataItem,"ID")%>' Text="Open Quote" />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn DataField="NULL" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>


Now I want to disable (Visible = false) the asp-button like this;

if (column["IsTransfer"] == true && column["IsOther]== true)
{
ButtonOpen.Visible = false;
}

I don't see how to access the button and how I check these column cell-values

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 20 Feb 2013, 04:12 AM
Hi,

Please take a look into the following code snippet.

C#:
protected void RadGridQuotes_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataitem = (GridDataItem)e.Item;
        CheckBox IsTransfer = (CheckBox)dataitem["IsTransfer"].Controls[0];
        CheckBox IsOther = (CheckBox)dataitem["IsOther"].Controls[0];
        if (IsTransfer.Checked && IsOther.Checked)
        {
            Button btn = (Button)dataitem.FindControl("ButtonOpen");
            btn.Visible = false;
        }
    }
}

Thanks,
Shinu.
0
Pascal
Top achievements
Rank 1
answered on 20 Feb 2013, 08:13 AM
Thank you Shinu, I had spent a lot of time to search for an answer, this works like a charm!
Tags
Grid
Asked by
Pascal
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Pascal
Top achievements
Rank 1
Share this question
or