Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
920
e.CurrentSelectedRows[0].Index raises null error
posted

Hi,

In server side code I have tried to retrieve the index of the select row but always get a null reference error on the statement to get the index.  Here is the code that I have been tryying (with debut ptint statements to try and find the problem.

 When I look at the e.CurrentSelectedRows in Quick Watch it shows there is a count of 1.

protected void gridCompany_RowSelectionChanged(object sender, SelectedRowEventArgs e)

{

Int32 ri = 0;

if (e.CurrentSelectedRows != null)

{

if (e.CurrentSelectedRows[0] == null)

System.Diagnostics.Debug.Print("Current selected row[0] is null but count is {0}", e.CurrentSelectedRows.Count);

else

// never hit this

// if not checking for null, this raises null reference error

ri = e.CurrentSelectedRows[0].Index;

}

System.Diagnostics.Debug.Print("Active row index {0}", ri);

// this raises error

ri = gridCompany.Behaviors.Selection.SelectedRows[0].Index;

Guid companyGuid = Guid.Parse(gridCompany.Rows[ri].DataKey.ToString());

FillGridUsers(companyGuid);

}

Parents
  • 920
    Offline posted

    One more piece of information.

    When I put a breakpoint before the statement that is trying to get the index of the selected row and I look at the e.CurrentSelectedRows in Quick View I do see the value of the selected row index in "_idPairs[1].value" and the "Key" of _idPairs[1] is the index of the selected record on the page.

    I have tried with with EnableDataViewState set to true and false and they both work the same way.  In all cases the EnableViewState for the grid itself is true.

    Thanks - NormD

Reply Children