Friday, 15 February 2013

asp.net - Datagrid row not being read code -


I have the following code ...

  SAFE sub GridView1_RowUpdating (ByVal as this object , ByVal e as EventArgs) handles integer as GridView1.RowUpdating dim SocioNumInfo = CInt (GridView1.Rows (GridView1.SelectedIndex) .Cells (4) .text) MsgBox (SocioNumInfo.ToString) ... End Sub  

The index was out of range was less than the non-negotiable and the size of the collection. Parameter name: index

MsgBox just end up being read data that there should me to check in the day that it is a parameter so I can add DB. ..but still .. nothing. Is this the right code to read directly from a cell in a row? In the "protected sub" area, I tried the pre-selected Ink Exchanges and Row editing ... and still nothing. Still throws an error on me

If I try as dim SocioNumInfo string = CSTR (GridView1.Rows (GridView1.SelectedRow) .Cells (4) .text) This gives me an "integer Can not be changed "Error

If there is no row selected GridView1 selected index to -1 . You may have to add a check

  if gridview1 Selected index & lt; & Gt; -1 then use 'GridView1.SelectedIndex ending here then   

However, it is easy to access the selected row like this:

  Slow Line = GridView1 SelectedRow row is not IsNumeric nothing andalso (row.Cells (2) .text) then dim SocioNumInfo Integer = CInt (row.Cells (2) as .text) .... Finally, if   

Note that the cell index is zero-based. row.Cells (4) is in the 5th column.

No comments:

Post a Comment