View Full Version : [CLOSED] DataGrid - selecting first record does not set SelectedIndex

Oct 10, 2013, 2:19 PM

We are having a DataGrid problem:
When user selects first displayed item in the grid, the SelectedIndex value is not set correctly.
When user selects any other item in the grid, the SelectedIndex value is set correctly.

Please note that we have not been able to recreate this problem with test data.

Here is the Page Source listing, created by running the page with the problem datagrid in Firefox and pressing CTL-U:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<link type="text/css" rel="stylesheet" href="/stage/vaExt/extjs/resources/ext_theme_gray/ext-theme-gray-all-embedded-css/ext.axd?v=40838" id="ext-theme" />
<link type="text/css" rel="stylesheet" href="/stage/vaExt/extnet/resources/css/extnet-all-embedded-css/ext.axd?v=40838" />
<script type="text/javascript" src="/stage/vaExt/extjs/ext-all-js/ext.axd?v=40838"></script>
<script type="text/javascript" src="/stage/vaExt/extnet/extnet-all-js/ext.axd?v=40838"></script>
<link rel="stylesheet" href="VAStyle.css" />

<script type="text/javascript">
Ext.net.ResourceMgr.init({id:"rmModuleOpen",aspForm:"formModuleOpen",theme:"gray",appName:"stage/vaExt"});Ext.onReady(function(){Ext.create("Ext.net.Viewport",{id:"viewportVA",renderTo:Ext.get("formModuleOpen"),items:[],layout:"border"});Ext.net.Notification.show({"title":"ModuleOpen:Subscription Valid","html":" : NingID=3fl8yypivl6rh : ModuleID=AssignmentsSummary : UserName=jharris : Role=student","header":true});Ext.net.ResourceMgr.destroyCmp("App.panelExtNet");App.viewportVA.add({"id":"panelExtNet","baseCls":"ExtDetailPage","loader":{"id":"loaderPanelExtNet","loadMask":{"showMask":true},"renderer":"frame","url":"AssignmentsSummary.aspx"},"anchor":"true true","region":"center","layout":"fit"});});
<form method="post" action="ModuleOpen.aspx?m=AssignmentsSummary" id="formModuleOpen">
<div class="aspNetHidden">



Here is the markup of the datagrid definition:

<ext:GridPanel ID="_grdAssignments" runat="server"
Visible="true" Hidden="false" >
<ext:Store ID="_storeAssignments" runat="server" >
<ext:Model ID="modelAssignments" runat="server"
<ext:ModelField Name="AssignmentID" Type="Int" />
<ext:ModelField Name="TeacherStudentName" />
<ext:ModelField Name="Category" />
<ext:ModelField Name="Description" />
<ext:ModelField Name="DateAssigned" Type="Date" DateFormat= "c" />
<ext:ModelField Name="DateDue" Type="Date" DateFormat="c"/>
<ext:ModelField Name="Status" />
<ext:ModelField Name="CurrentUserName" />
<ext:ModelField Name="TeachersNotes" />
<ext:ModelField Name="StudentsNotes" />
<ext:ModelField Name="Student_People_id" Type="Int" />
<ext:ModelField Name="Teacher_People_id" Type="Int"/>

<ext:Column ID="_colTeacherStudentName" runat="server" Text="TeacherStudentName"
DataIndex = "TeacherStudentName" Flex="90" />
<ext:Column ID="_colCategory" runat="server" Text="Category"
DataIndex = "Category" Flex="76" />
<ext:Column ID="_colDescription" runat="server" Text="Description"
DataIndex = "Description" Flex="200" />
<ext:DateColumn ID="_colDateAssigned" runat="server" Text="Assigned"
DataIndex = "DateAssigned" Flex="65" Format="MM/dd/yyyy" />
<ext:DateColumn ID="_colDateDue" runat="server" Text="Due"
DataIndex = "DateDue" Flex="65" Format="MM/dd/yyyy" />
<ext:Column ID="_colStatus" runat="server" Text="Status"
DataIndex = "Status" Flex="70" />
<ext:Column ID="_colTeachersNotes" runat="server" Text="TeacherNotes"
DataIndex = "TeachersNotes" Flex="5" Hidden="true" />
<ext:Column ID="_colStudentsNotes" runat="server" Text="StudentNotes"
DataIndex = "StudentsNotes" Flex="5" Hidden="true" />

<ext:Column ID="_colStudentPeopleID" runat="server" Text="Student ID"
DataIndex = "Student_People_id" Flex="5" Hidden="true" />
<ext:Column ID="colTeacherPeopleID" runat="server" Text="Teacher ID"
DataIndex = "Teacher_People_id" Flex="5" Hidden="true" />

<ext:RowSelectionModel ID="rsmAssignments" runat="server" Mode="Single">

<ext:GridView ID="GridView1"
EmptyText="No data to Display" />

And here is the cs code that sets the grid properties, and the event function called when the user pressed the "Modify" button:

// _grdAssignments
this._grdAssignments.X = 16;
this._grdAssignments.Y = 192;
this._grdAssignments.ColumnLines = true;
this._grdAssignments.AutoScroll = true;
this._grdAssignments.Height = 400;

protected void _btnModify_DirectClick(object sender, Ext.Net.DirectEventArgs e)
//Make sure user has selected a record, then open detail page and populate with selection
ext.MessageBoxConfig oMsg = new ext.MessageBoxConfig();

oMsg.Cls = "ExtMessageBox";
oMsg.Modal = true;
oMsg.Closable = true;
oMsg.Buttons = ext.MessageBox.Button.OK;
ext.RowSelectionModel sm = this._grdAssignments.GetSelectionModel() as ext.RowSelectionModel;
if (sm.SelectedIndex > 0)
string json = e.ExtraParams["Values"];

Dictionary<string, string>[] dicSelectedAssignment =
JSON.Deserialize<Dictionary<string, string>[]>(json);

StringBuilder sb = new StringBuilder();
foreach (Dictionary<string, string> row in dicSelectedAssignment)
oMsg.Icon = ext.MessageBox.Icon.WARNING;
oMsg.Message = "Please select an assignment to MODIFY";

When the above function is called after the user has selected the FIRST ROW, they get the warning message box
When the above function is called after the user selects ANY OTHER ROW, they get the detailed screen

Please note that this bug always applies to the FIRST DISPLAYED ROW, regardless of the sort.
If the records are in order A, B, C then selecting the "A" record and trying to modify it gives the warning message
If the records are in order C, B, A then the user can successfully select and modify record "A", but gets a warning message on record "C"

Oct 10, 2013, 4:16 PM
Hi @VirtualArtists,

When user selects first displayed item in the grid, the SelectedIndex value is not set correctly.

What is the value there?

Oct 11, 2013, 12:32 AM
The value is 0 (zero).

Oct 11, 2013, 2:07 AM

Try to use getCurrentPosition method: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.selection.RowModel-method-getCurrentPosition

App.GridPanel1.getSelectionModel().getCurrentPosit ion().row

Oct 11, 2013, 5:50 AM
The value is 0 (zero).

It is expected. Just zero-based indexing. "0" means that the first row is selected.