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

Disabling Checkbox in Template Column

3 Answers 400 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rodney
Top achievements
Rank 2
Rodney asked on 30 Mar 2016, 03:27 PM

I've looked at a number of posts here on doing this and just can't seem to get it to work. But I have inside of a GridTemplateColumn and based on the value of one of the data columns I want to set it to disabled. My data values are either "OPEN" or "CLOSED". The checkbox in question is cbMarkCompleted and the datavalue I'm checking is TaskStatusTypeCode So here is my current code:

 

<Columns>
    <telerik:GridBoundColumn UniqueName="NotificationId" DataField="NotificationId" DataType="System.Int32"
        display="false" />
    <telerik:GridTemplateColumn UniqueName="MARKCOMPLETED" ShowFilterIcon="false" HeaderText="Mark Completed"
        HeaderStyle-Width="65">
        <FilterTemplate>
            <asp:CheckBox ID="cbAll" runat="server" onclick="CheckAll(this)" />
        </FilterTemplate>
        <ItemTemplate>
            <asp:CheckBox ID="cbMarkCompleted" runat="server" ></asp:CheckBox>
        </ItemTemplate>
    </telerik:GridTemplateColumn>
    <telerik:GridBoundColumn UniqueName="NOTIFICATIONTYPE" HeaderText="Type" DataField="NOTIFICATIONTYPE" ShowFilterIcon="false"
        CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" SortExpression="NOTIFICATIONTYPE" HeaderStyle-Width="80"/>
    <telerik:GridBoundColumn UniqueName="DISPLAYTEXT" HeaderText="Text" DataField="DISPLAYTEXT" ShowFilterIcon="false"
        CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" SortExpression="DISPLAYTEXT" HeaderStyle-Width="340"/>
    <telerik:GridDateTimeColumn UniqueName="CREATEDON" HeaderText="Created On" DataField="CREATEDON" ShowFilterIcon="false"
        DataFormatString="{0:dd MMM yyyy}" DataType="System.DateTime" HtmlEncode="false" ItemStyle-CssClass="center"
        CurrentFilterFunction="GreaterThanOrEqualTo" AutoPostBackOnFilter="true" HeaderStyle-Width="100"/>
    <telerik:GridDateTimeColumn UniqueName="MODIFIEDON" HeaderText="Last Update" DataField="MODIFIEDON" ShowFilterIcon="false"
        DataFormatString="{0:dd MMM yyyy}" DataType="System.DateTime" HtmlEncode="false" ItemStyle-CssClass="center"
        CurrentFilterFunction="GreaterThanOrEqualTo" AutoPostBackOnFilter="true" HeaderStyle-Width="100"/>
    <telerik:GridDateTimeColumn UniqueName="DUEDATE" HeaderText="Due Date" DataField="DUEDATE" ShowFilterIcon="false"
        DataFormatString="{0:dd MMM yyyy}" DataType="System.DateTime" HtmlEncode="false" ItemStyle-CssClass="center"
        CurrentFilterFunction="GreaterThanOrEqualTo" AutoPostBackOnFilter="true" HeaderStyle-Width="100"/>
    <telerik:GridTemplateColumn UniqueName="ENTITYTYPE" ShowFilterIcon="false" DataField="ENTITYTYPE"
        SortExpression="ENTITYTYPE" HeaderText="Notification For" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"
        HeaderStyle-Width="75">
        <ItemTemplate>
            <asp:LinkButton ID="lnkNavigateToItem" runat="server" CommandName="NAVIGATE" Text='<%# Eval("EntityType") %>'
             CommandArgument='<%# Eval("ENTITYID") + "," + Eval("EntityTypeCode") %>' />
            <asp:Label ID="lblEntityType" runat="server" Text='<%# Eval("EntityType") %>'></asp:Label>
        </ItemTemplate>
    </telerik:GridTemplateColumn>
    <telerik:GridBoundColumn UniqueName="ENTITYTYPECODE" Visible="false" HeaderText="" DataField="ENTITYTYPECODE" ShowFilterIcon="false"
        CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" SortExpression="ENTITYTYPECODE"/>
    <telerik:GridBoundColumn UniqueName="TaskStatusTypeCode" Visible="false" HeaderText="" DataField="TaskStatusTypeCode" ShowFilterIcon="false"
        CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" SortExpression="TaskStatusTypeCode" HtmlEncode="true" />
</Columns>     

3 Answers, 1 is accepted

Sort by
0
Rodney
Top achievements
Rank 2
answered on 30 Mar 2016, 03:29 PM

Forgot the C# Code, fails with is null for the Check Box:

protected void rdNotificationList_ItemCreated(object sender, GridItemEventArgs e)
{
        GridDataItem item = (GridDataItem)e.Item;
        if ((((DataRowView)e.Item.DataItem)["TaskStatusTypeCode"]).ToString() == "OPEN")
        {
            CheckBox chkBox = (CheckBox)item["cbMarkCompleted"].Controls[0];
            chkBox.Enabled = false;
        }
    }
}

0
Konstantin Dikov
Telerik team
answered on 04 Apr 2016, 05:43 AM
Hello Rodney,

First, within the OnItemCreated and OnItemDataBound events you need to ensure that the item that fires the event is GridDataItem, before proceeding with your code. Secondly, within the OnItemCreated event, no data will be bound to the control, so you need to use the OnItemDataBound event instead.

Detailed information on how to access controls in RadGrid could be found in the following help article:
Hope this helps.


Regards,
Konstantin Dikov
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Rodney
Top achievements
Rank 2
answered on 05 Apr 2016, 12:21 PM

Thank you. 

Adding the test for GridDataItem, fixed my problem.

Rodney

Tags
Grid
Asked by
Rodney
Top achievements
Rank 2
Answers by
Rodney
Top achievements
Rank 2
Konstantin Dikov
Telerik team
Share this question
or