Radgrid Get Selected Checkbox on postback

3 posts, 0 answers
  1. Roger
    Roger avatar
    10 posts
    Member since:
    Apr 2019

    Posted 01 Oct 2019 Link to this post

    I have a RadGrid in a user control on a webpage

     

    1. The radgrid has one template GridHyperLinkColumn and many other columns loaded from the datatable.

    2. The grid loads successfully from a Datatable with the template column.

    3. I have a Checkbox column and it shows well.

    4. Button click calls MarkSelectedInvalid()

    ** It never gets inside the For Loop as the RadGrid1.MasterTableView.Items is zero.  I have enabledviewstate on page, and in HTML Mark up for RadGrid.

     

    <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="false" AllowMultiRowEdit = "true"
            SortingSettings-SortedBackColor="#999999" OnPreRender="RadGrid1_PreRender"
            CellSpacing="-1" GridLines="Both" Font-Size="xx-Small"
            EnableViewState="true" ViewStateMode="Enabled">
            <GroupingSettings CollapseAllTooltip="Collapse all groups" />
            <SortingSettings SortedBackColor="153, 153, 153" />
            <MasterTableView EditMode="InPlace" EnableColumnsViewState="true"
                EnableViewState="true">
                <RowIndicatorColumn Visible="False">
                </RowIndicatorColumn>
                <ExpandCollapseColumn Created="True">
                </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridHyperLinkColumn DataNavigateUrlFields="Path" DataTextField="Path"
                        FilterControlAltText="Filter Path column" HeaderText="Path"
                        SortExpression="Path" Target="_blank" UniqueName="Path1">
                    </telerik:GridHyperLinkColumn>
                </Columns>
            </MasterTableView>
            </telerik:RadGrid>

     

     

    Code:  

    private void MarkSelectedItemsInvalid()
           {
               foreach (GridDataItem item in this.RadGrid1.MasterTableView.Items)
               {
                   TableCell cell = item["MarkInvalid"];
                   CheckBox checkBox = (CheckBox)cell.Controls[0];
                   if (checkBox.Checked)
                   {
                       string path = (item["Path"].FindControl("TB_Path") as TextBox).Text;
                       string title = (item["Title"].FindControl("TB_Title") as TextBox).Text;
                       item.Enabled = false;
                       var dictionary = new Dictionary<string, string>();
                       dictionary.Add("ContentTypeId", GetContentTypeID(qsURLSite, GetLibraryFromURL(path), "Invalid"));
                       UpdateMetaData(path,GetLibraryFromURL(path), dictionary);
                   }
               }
           }
  2. Eyup
    Admin
    Eyup avatar
    3892 posts

    Posted 04 Oct 2019 Link to this post

    Hi Roger,

     

    Your logic seems correct. Actually, this is probably related to the binding of the grid. Could you check whether you have DataBind() method for the grid in the code-behind and remove it?
    https://www.telerik.com/support/kb/aspnet-ajax/grid/details/how-to-bind-radgrid-properly-on-server-side

    Feel free to give it a try and let me know about the outcome.

     

    Regards,
    Eyup
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Roger
    Roger avatar
    10 posts
    Member since:
    Apr 2019

    Posted 04 Oct 2019 in reply to Eyup Link to this post

    I found my issue was with enableviewstate was set to false in a parent page. 

     

    It overrides the viewstate set on the control Its self.

     

    Roger

Back to Top