SelectedIndexChanged event of RadGrid

8 posts, 0 answers
  1. zpc
    zpc avatar
    2 posts
    Member since:
    Jul 2009

    Posted 11 Sep 2011 Link to this post

    Hi,

    SelectedIndexChanged event of RadGrid is not fired.
    Please help me with an example how to fire SelectedIndexChanged event of RadGrid.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 Sep 2011 Link to this post

    Hello,

    The SelectedIndexChanged event will be fired when you click the row if you have set EnablePostBackOnRowClick property to True.
    aspx:
    <ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true">
    </ClientSettings>
    C#:
    protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
    {
       GridDataItem item =(GridDataItem )RadGrid1.SelectedItems[0];//get selected row
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michael
    Michael avatar
    2 posts
    Member since:
    Aug 2013

    Posted 20 Mar 2014 Link to this post

    How would you fire the Selected Index Change (i.e. the user clicks on a Row in the RadGrid) without using a PostBack?  The PostBack is not acceptable in my situation, therefore this method is not going to work for me because it triggers the PostBack on the page.

    I need to listen to this event without a PostBack being called.
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Mar 2014 in reply to Michael Link to this post

    Hi Michael,

    Please try to ajaxify the RadGrid to achieve your scenario.

    ASPX:
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1"                                                           AutoGenerateColumns="true" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged">
        <ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true">
        </ClientSettings>
    </telerik:RadGrid>

    C#:
    protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridDataItem item = (GridDataItem)RadGrid1.SelectedItems[0];//get selected row
    }

    Thanks,
    Shinu.
  6. Michael
    Michael avatar
    2 posts
    Member since:
    Aug 2013

    Posted 21 Mar 2014 in reply to Shinu Link to this post

    The post back is still being fired (I know because the Loading Panel overlay appears).

    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" HorizontalAlign="NotSet" LoadingPanelID="RadAjaxLoadingPanel2">
       <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" 
                CellSpacing="0" OnNeedDataSource="RadGrid1_NeedDataSource" CssClass="RemoveBorders" 
                OnItemDataBound="RadGrid1_ItemDataBound" OnPreRender="RadGrid1_PreRender" 
                GridLines="None" Width="770px"  OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged">
                <ClientSettings EnablePostBackOnRowClick="true">
                    <Selecting AllowRowSelect="true"></Selecting>
                </ClientSettings>
                <MasterTableView>
                    <Columns>






  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Mar 2014 in reply to Michael Link to this post

    Hi Michael,

    Unfortunately I couldn't replicate the issue at my end. Please have a look into the sample code snippet which works fine at my end.

    ASPX:
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default">
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
        <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1"                          AutoGenerateColumns="true" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged">
            <ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true">
            </ClientSettings>
        </telerik:RadGrid>
    </telerik:RadAjaxPanel>
    protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Thread.Sleep(1000);
        //your code
    }

    Please try the posted code and let me know it is working or not. Please provide your full code if it doesn't help.
    Thanks,
    Princy.
  8. Hori
    Hori avatar
    6 posts
    Member since:
    Apr 2016

    Posted 02 May Link to this post

    Im always getting an error of System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. in the line of 

          GridDataItem selectedItem = (GridDataItem)vListRadGridChk.SelectedItems[0];

  9. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 04 May Link to this post

    Hi Hori,

    The error you are seeing could be observed if an item is not selected in the grid. However, it would be hard to pinpoint what is causing it without further investigation.

    Would you send us a runnable sample where the issue you are seeing us replicated? Alternatively you can provide the relevant markup with the code-behind. Thus we can examine the code and look for what could cause the behavior.

    Regards,
    Viktor Tachev
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017