Porblema con un datagrid

29/07/2004 - 01:04 por Roberto Londono | Informe spam
Hola amigos, tengo un problema con el datagrid.
Yo cree un datagrid y le adicion un boton Select y Paging

Mi problema es que cuando yo tengo mas de 10 elementos en
el datagrid el me genera una nueva pagina. Yo intengo
selecionarla y me ejecuta le boton de select.
Pero si yo ejecuto el boton de select en los primeros 10
elementos (primera pagina) no me da ningun error.

El error que sale cuando trato de cambiar la pagina es el
siguiente.

Specified argument was out of the range of valid values.
Parameter name: index
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException:
Specified argument was out of the range of valid values.
Parameter name: index

Source Error:


Line 312:
Line 313:
Line 314: CodCard = e.Item.Cells(1).Text
Line 315: TBCardNo.Text = CodCard
Line 316:

Y El codigo que esta utilizando es:
Paging :


Private Sub MasterGrid_PageIndexChanged1(ByVal source As
Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEventArgs)
Handles MasterGrid.PageIndexChanged


Me.SqlDataAdapter1.SelectCommand.Parameters.Add
("@Date_Need1", System.Data.SqlDbType.DateTime, 8).Value
= TBDate1.Text

Me.SqlDataAdapter1.SelectCommand.Parameters.Add
("@Date_Need2", System.Data.SqlDbType.DateTime, 8).Value
= TBDate2.Text

'MasterGrid.DataSource = GetLogVisitor
(TBDate1.Text, TBDate2.Text)

MasterGrid.CurrentPageIndex = e.NewPageIndex
MasterGrid.DataSource =
MeS_HR_DS_View_IdenticationVisitorlog1
SqlDataAdapter1.Fill
(MeS_HR_DS_View_IdenticationVisitorlog1)
MasterGrid.DataBind()
MasterGrid.Enabled = True
End Sub

*******************
Boton Select
*********************************************************


Private Sub MasterGrid_ItemCommand1(ByVal source As
Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Handles MasterGrid.ItemCommand
'Dim Itm As Integer

' Itm = e.Item.ItemIndex()
'Dim keys As DataKeyCollection
'keys = MasterGrid.DataKeys

Dim CodCard As String
'CodCard = Me.MasterGrid.SelectedItem.Cells
(0).Text
CodCard = e.Item.Cells(1).Text
TBCardNo.Text = CodCard
MasterGrid.Enabled = True
DGDetail.DataSource = GetVisitorDetail
(TBDate1.Text, TBDate2.Text, TBCardNo.Text)
' SqlDataAdapter1.Fill
(MeS_HR_DS_ViewIdenticationVisitorlog1)
DGDetail.DataBind()
DGDetail.Enabled = True
End Sub

Preguntas similare

Leer las respuestas

#1 GastonQ
29/07/2004 - 04:43 | Informe spam
Hola, creo saber que es lo que te está pasando.

Tienes que hacer una validación al cambiar la propiedad CurrentPageIndex.

Esto se debe a que si vuelves a cargar el DataGrid, con el resultado de una
consulta que tiene menos registros que la consulta inicial, se produce este
error que mencionas. Básicamente la validación es que si la página actual es
mayor que el total de registros del DataGrid dividido por el valor de la
propiedad PageSize, entonces debes volver a la página 1.

Te paso un metodito que hice para un proyecto:

public void CheckPaging( DataGrid dgSource, DataSet dtsSource, string
tableName )
{
if( dgSource.AllowPaging )
{
// Si la página no existe retorna la primera.
if( dgSource.CurrentPageIndex > ( dtsSource.Tables[
tableName ].Rows.Count / dgSource.PageSize ) )
{
dgSource.CurrentPageIndex = 0;
}
}
}

Saludos
Gaston Quirque
Microsoft MVP


"Roberto Londono" escribió en el
mensaje news:62ef01c474f7$3177b790$
Hola amigos, tengo un problema con el datagrid.
Yo cree un datagrid y le adicion un boton Select y Paging

Mi problema es que cuando yo tengo mas de 10 elementos en
el datagrid el me genera una nueva pagina. Yo intengo
selecionarla y me ejecuta le boton de select.
Pero si yo ejecuto el boton de select en los primeros 10
elementos (primera pagina) no me da ningun error.

El error que sale cuando trato de cambiar la pagina es el
siguiente.

Specified argument was out of the range of valid values.
Parameter name: index
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException:
Specified argument was out of the range of valid values.
Parameter name: index

Source Error:


Line 312:
Line 313:
Line 314: CodCard = e.Item.Cells(1).Text
Line 315: TBCardNo.Text = CodCard
Line 316:

Y El codigo que esta utilizando es:
Paging :


Private Sub MasterGrid_PageIndexChanged1(ByVal source As
Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEventArgs)
Handles MasterGrid.PageIndexChanged


Me.SqlDataAdapter1.SelectCommand.Parameters.Add
("@Date_Need1", System.Data.SqlDbType.DateTime, 8).Value
= TBDate1.Text

Me.SqlDataAdapter1.SelectCommand.Parameters.Add
("@Date_Need2", System.Data.SqlDbType.DateTime, 8).Value
= TBDate2.Text

'MasterGrid.DataSource = GetLogVisitor
(TBDate1.Text, TBDate2.Text)

MasterGrid.CurrentPageIndex = e.NewPageIndex
MasterGrid.DataSource > MeS_HR_DS_View_IdenticationVisitorlog1
SqlDataAdapter1.Fill
(MeS_HR_DS_View_IdenticationVisitorlog1)
MasterGrid.DataBind()
MasterGrid.Enabled = True
End Sub

*******************
Boton Select
*********************************************************


Private Sub MasterGrid_ItemCommand1(ByVal source As
Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Handles MasterGrid.ItemCommand
'Dim Itm As Integer

' Itm = e.Item.ItemIndex()
'Dim keys As DataKeyCollection
'keys = MasterGrid.DataKeys

Dim CodCard As String
'CodCard = Me.MasterGrid.SelectedItem.Cells
(0).Text
CodCard = e.Item.Cells(1).Text
TBCardNo.Text = CodCard
MasterGrid.Enabled = True
DGDetail.DataSource = GetVisitorDetail
(TBDate1.Text, TBDate2.Text, TBCardNo.Text)
' SqlDataAdapter1.Fill
(MeS_HR_DS_ViewIdenticationVisitorlog1)
DGDetail.DataBind()
DGDetail.Enabled = True
End Sub
Respuesta Responder a este mensaje
#2 Roberto Londono
29/07/2004 - 19:06 | Informe spam
Hola Gaston, Muchas gracias por tu ayuda.

Yo copie tu codigo y lo converti a VB y lo coloque

Private Sub MasterGrid_ItemCommand1, antes de que se
genera el error, pero el no entra en el segundo IF y
continua y da el error.

Pero una cosa curiosa es que yo quito Private Sub
MasterGrid_ItemCommand1, y solo dejo el Private Sub
MasterGrid_PageIndexChanged1, me funciona bien me cambia
de pagina. me asalta una duda no sera esto bug de VS.
y la segunda no se si lo coloque donde lo debo colocar.

de nuevo muchas gracias.

Roberto Londono



Hola, creo saber que es lo que te está pasando.

Tienes que hacer una validación al cambiar la propiedad


CurrentPageIndex.

Esto se debe a que si vuelves a cargar el DataGrid, con


el resultado de una
consulta que tiene menos registros que la consulta


inicial, se produce este
error que mencionas. Básicamente la validación es que si


la página actual es
mayor que el total de registros del DataGrid dividido


por el valor de la
propiedad PageSize, entonces debes volver a la página 1.

Te paso un metodito que hice para un proyecto:

public void CheckPaging( DataGrid dgSource, DataSet


dtsSource, string
tableName )
{
if( dgSource.AllowPaging )
{
// Si la página no existe retorna la primera.
if( dgSource.CurrentPageIndex > (


dtsSource.Tables[
tableName ].Rows.Count / dgSource.PageSize ) )
{
dgSource.CurrentPageIndex = 0;
}
}
}

Saludos
Gaston Quirque
Microsoft MVP


"Roberto Londono"


escribió en el
mensaje news:62ef01c474f7$3177b790$
Hola amigos, tengo un problema con el datagrid.
Yo cree un datagrid y le adicion un boton Select y




Paging

Mi problema es que cuando yo tengo mas de 10 elementos




en
el datagrid el me genera una nueva pagina. Yo intengo
selecionarla y me ejecuta le boton de select.
Pero si yo ejecuto el boton de select en los primeros




10
elementos (primera pagina) no me da ningun error.

El error que sale cuando trato de cambiar la pagina es




el
siguiente.

Specified argument was out of the range of valid




values.
Parameter name: index
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException:
Specified argument was out of the range of valid




values.
Parameter name: index

Source Error:


Line 312:
Line 313:
Line 314: CodCard = e.Item.Cells(1).Text
Line 315: TBCardNo.Text = CodCard
Line 316:

Y El codigo que esta utilizando es:
Paging :


Private Sub MasterGrid_PageIndexChanged1(ByVal source




As
Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEventArgs)
Handles MasterGrid.PageIndexChanged


Me.SqlDataAdapter1.SelectCommand.Parameters.Add
("@Date_Need1", System.Data.SqlDbType.DateTime,




8).Value
= TBDate1.Text

Me.SqlDataAdapter1.SelectCommand.Parameters.Add
("@Date_Need2", System.Data.SqlDbType.DateTime,




8).Value
= TBDate2.Text

'MasterGrid.DataSource = GetLogVisitor
(TBDate1.Text, TBDate2.Text)

MasterGrid.CurrentPageIndex = e.NewPageIndex
MasterGrid.DataSource >> MeS_HR_DS_View_IdenticationVisitorlog1
SqlDataAdapter1.Fill
(MeS_HR_DS_View_IdenticationVisitorlog1)
MasterGrid.DataBind()
MasterGrid.Enabled = True
End Sub

*******************
Boton Select





*********************************************************


Private Sub MasterGrid_ItemCommand1(ByVal source As
Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Handles MasterGrid.ItemCommand
'Dim Itm As Integer

' Itm = e.Item.ItemIndex()
'Dim keys As DataKeyCollection
'keys = MasterGrid.DataKeys

Dim CodCard As String
'CodCard = Me.MasterGrid.SelectedItem.Cells
(0).Text
CodCard = e.Item.Cells(1).Text
TBCardNo.Text = CodCard
MasterGrid.Enabled = True
DGDetail.DataSource = GetVisitorDetail
(TBDate1.Text, TBDate2.Text, TBCardNo.Text)
' SqlDataAdapter1.Fill
(MeS_HR_DS_ViewIdenticationVisitorlog1)
DGDetail.DataBind()
DGDetail.Enabled = True
End Sub




.

email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida