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

OnSelectedIndexChanged can't find Selected row

1 Answer 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric Klein
Top achievements
Rank 1
Eric Klein asked on 19 Nov 2009, 05:46 PM
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.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Nov 2009, 06:17 AM
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.
Tags
Grid
Asked by
Eric Klein
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or