Disabling Checkbox in Template Column

4 posts, 0 answers
  1. Rodney
    Rodney avatar
    40 posts
    Member since:
    Mar 2015

    Posted 30 Mar Link to this post

    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 a asp:CheckBox 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>     

  2. Rodney
    Rodney avatar
    40 posts
    Member since:
    Mar 2015

    Posted 30 Mar in reply to Rodney Link to this post

    Forgot the C# Code, fails with objet 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;
            }
        }
    }

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1803 posts

    Posted 04 Apr Link to this post

    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.
  5. Rodney
    Rodney avatar
    40 posts
    Member since:
    Mar 2015

    Posted 05 Apr in reply to Konstantin Dikov Link to this post

    Thank you. 

    Adding the test for GridDataItem, fixed my problem.

    Rodney

Back to Top