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

Radgrid Get Selected Checkbox on postback

2 Answers 207 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Roger asked on 01 Oct 2019, 05:56 PM

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 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 04 Oct 2019, 08:40 AM

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.
0
Roger
Top achievements
Rank 2
Iron
Iron
Iron
answered on 04 Oct 2019, 01:54 PM

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

Tags
Grid
Asked by
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Eyup
Telerik team
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or