0
votes

I have several pages that share a user control. When the user clicks a save button on the user control, I need to be able to loop the items of a Radgrid on the parent page and get the selected items. The radgrid has a checkbox column. I can see that I am getting values from the grid cells but for some reason the checked value on the checkbox is always false even when it is checked. This same foreach code works when called from the parent page itself but not from the usercontrol.

Here is a code snippet.

RadGrid ProjectGrid = (RadGrid) this.Parent.FindControl("ProjectGrid");

        foreach (GridDataItem item in ProjectGrid.MasterTableView.Items)
        {
            string applicationPackageId = item.Cells[4].Text.ToString();

            CheckBox chbx = item.FindControl("ProjectGridCheckBox") as CheckBox;

            if (chbx != null && chbx.Checked)
            {
                numCheckedPackages++;
            }
        }

Here is my grid.

<telerik:RadGrid ID="ProjectGrid" runat="server" Skin="WF" ShowHeader="true" EnableEmbeddedSkins="false" AllowSorting="false" AllowFilteringByColumn="false" AllowMultiRowSelection="true">
    <MasterTableView Width="100%" CommandItemDisplay="None" AutoGenerateColumns="false" TableLayout="Fixed">
        <RowIndicatorColumn Visible="False">
            <HeaderStyle Width="20px" />
        </RowIndicatorColumn>
        <ExpandCollapseColumn Resizable="False" Visible="False">
            <HeaderStyle Width="20px" />
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridTemplateColumn UniqueName="SelectColumn" DataField="Id" HeaderStyle-Width="5%" >  
                <ItemTemplate>  
                    <asp:CheckBox ID="ProjectGridCheckBox"   runat="server"/>  
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn DataField="Package.ProjectPackageNumberNameDisplayField" HeaderText="Project - Package" UniqueName="ProjectPackages"  HeaderStyle-Width="85%"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ApplicationPackageID" HeaderText="Id" HeaderStyle-Width="15%" UniqueName="PackageId"></telerik:GridBoundColumn>                                    
        </Columns>
    </MasterTableView>
    <ClientSettings EnableRowHoverStyle="true">
        <Selecting AllowRowSelect="True" />
    </ClientSettings>
    <HeaderStyle BackColor="#666666" Font-Names="verdana, arial" Font-Size="Small" Height="20px" />
</telerik:RadGrid>
In which event you check this? - Tomas Voracek
It's on a button click event in the usercontrol. So the user selects items in the grid, enters some data in the usercontrol and clicks a submit button on the usercontrol. Only one page that holds the usercontrol, has this grid on it so based on some conditional code, this code gets run but from inside the usercontrol. - Rhonda
How are you binding data to grid? In Page_Load? If so, you must have binding wrapped in if(!Page.IsPostBack), otherwise you overwrite data sent by client with data from datasource. Post more code please. - Tomas Voracek
My bet is this has to do with the control execution lifecycle. It may be possible that your parent page grid is not bound, or not updated, at the moment that your user control is firing its event. - SouthShoreAK
The binding code is inside !Page.IsPostBack. - Rhonda