OnSelectedIndexChanged can't find Selected row

2 posts, 0 answers
  1. Eric Klein
    Eric Klein avatar
    183 posts
    Member since:
    Aug 2009

    Posted 19 Nov 2009 Link to this post

    I have a grid on my page
    <telerik:RadGrid ID="RadGrid1" AllowFilteringByColumn="true" Skin="Vista" runat="server" EnableViewState="false" GridLines="None"   
     AllowPaging="true" AllowSorting="true" PageSize="6" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged" > 
        <AlternatingItemStyle BackColor="#EEEEEE"></AlternatingItemStyle> 
        <ClientSettings EnablePostBackOnRowClick="true">  
           <Selecting AllowRowSelect="True"></Selecting> 
           <ClientEvents OnCommand="RadGrid1_Command" /> 
        </ClientSettings> 
        <MasterTableView HierarchyLoadMode="Client" ClientDataKeyNames="DuplicateStatementID">  
           <Columns> 
              <telerik:GridBoundColumn AllowFiltering="false" SortExpression="DuplicateStatementID" 
                       DataField="DuplicateStatementID" HeaderText="ID" DataType="System.Int32" Visible="false" /> 
              <telerik:GridBoundColumn SortExpression="Year" DataField="Year" HeaderText="Year" UniqueName="RGYear">  
                <ItemStyle Width="50px" /> 
              </telerik:GridBoundColumn> 
              <telerik:GridBoundColumn SortExpression="MonthName" DataField="MonthName" HeaderText="Month">  
           </Columns> 
        </MasterTableView> 
        <PagerStyle AlwaysVisible="true" /> 
    </telerik:RadGrid> 

    When I click on a row in the grid it fires the OnSelectedIndexChanged

            protected void RadGrid1_SelectedIndexChanged(object sender, System.EventArgs e)  
            {  
                 
              GridDataItem item = RadGrid1.SelectedItems[0] as GridDataItem;  
              string s = item["RGYear"].Text;    
     
              }           

    The problem is it claims nothing has been selected.  when I jump over the code I can see the row get seledted and then deselected.
    I am trying to set it up so that when the user clicks on a row in the grid it will take that data from the grid and populate some text boxes on the screen.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 Nov 2009 Link to this post

    Hello Eric,

    The SelectedItems collection is updated on server-side after a postback occurs. But when the ViewState of the control is disabled, the selected items count(client-side selection), would be equal to zero. Hence, you can either set the EnableViewState property of the grid to True or perform selection on server-side.

    Hope this helps..
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top