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

Problem with accessing selected rows on postback

1 Answer 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 14 Jul 2015, 09:40 AM

Hi.
I’m working on a legacy system trying to edit an old feature.
I need to access the selected rows from a Radgrid on post back.
I’m using Telerik.Web.UI v4.0.30319
My Grid looks like this:

<telerik:RadGrid runat="server" ID="RadGridResourcesToChange" AllowPaging="True" PageSize="50" AllowSorting="False" Visible="False" AllowMultiRowSelection="True" OnNeedDataSource="RadGridResourcesToChange_NeedDataSource">
    <MasterTableView Width="100%" DataKeyNames="Resources">
        <Columns>
         <Telerik:GridClientSelectColumn UniqueName="ResourceId" />
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <Selecting AllowRowSelect="True"></Selecting>
        <ClientEvents OnRowSelecting="RowSelecting" />
    </ClientSettings>
    </telerik:RadGrid>​

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {               
                PanelAfterSearch.Visible = false;
            }
            else
            {
               RadGridResourcesToChange.Visible = true;
                            
            }
        }
 
        protected void Page_Init(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
 
            }
            else
            {
 
                SelectedIds = GetSelectedWorkdayIds().ToList();
            }
 
 
        }
 public IEnumerable<Guid> GetSelectedWorkdayIds()
        {
            
            List<Guid> ids = new List<Guid>();
            //Here is where I'm trying to access the selected rows.
            return ids;
        }

The user enters search criteria and then on post back I set the grid Visible=true, triggering the needDataSource, binding the result to the grid.
And then my problem occurs, the user can then select rows, and click a button. I would then like to access the selected rows, performing my calculation.
I have tried using:
RadGridResourcesToChange.SelectedItems
RadGridResourcesToChange.MasterTableView.Items
Everything ends up empty on post back.
/ Martin

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 17 Jul 2015, 07:12 AM
Hi Martin,

The Page's Init event handler is too early in the page's life cycle and that is why your SelectedIndexes/SelectedItems collections are empty. The selected items information will be available within the Page's Load event handler, so if it is acceptable in your scenario, you could just move the logic for accessing the collection in that event.

However, if you need to handle this in the Page's Init event handler you will need to retrieve the items indexes on the client-side OnRowSelected event for example, store those IDs in a HiddenField controls and retrieve the value of that HiddenField with Request.Form.Get method.

Hope this helps.


Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Martin
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or