startuga Posted July 25, 2013 at 04:29 PM Report #519967 Posted July 25, 2013 at 04:29 PM Boa tarde pessoal, Ao tentar alterar o nome da coluna de uma tabela com este código , GridView1.Columns(0).HeaderText = "Home" Estou a enfrentar o seguinte erro: ArgumentOutOfRangeException was unhandled by user code Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index. Já tentei de tudo e não consigo resolver :x Obrigado ;
nelsonr Posted July 25, 2013 at 04:53 PM Report #519972 Posted July 25, 2013 at 04:53 PM Boas, e a grelha tem colunas?
veaoum Posted July 25, 2013 at 05:16 PM Report #519978 Posted July 25, 2013 at 05:16 PM Boa tarde pessoal, Ao tentar alterar o nome da coluna de uma tabela com este código , GridView1.Columns(0).HeaderText = "Home" Estou a enfrentar o seguinte erro: ArgumentOutOfRangeException was unhandled by user code Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index. Já tentei de tudo e não consigo resolver :x Obrigado ; Faz assim: GridView1.Columns.Item(0).HeaderText = "Home" Resulta? Quer dizer como tu tens também devia resultar. tens a certeza que o nome da tabela é mesmo esse?
startuga Posted July 26, 2013 at 07:40 AM Author Report #520034 Posted July 26, 2013 at 07:40 AM Não está a resultar continua com o mesmo erro! :c
nelsonr Posted July 26, 2013 at 08:34 AM Report #520038 Posted July 26, 2013 at 08:34 AM Faz debug com um breakpoint nessa linha. Selecciona o texto "GridView1.Columns", clica com o botão direito e faz "QuickWatch...". Ai consegues ver o conteúdo da variavel e ver se tem colunas.
startuga Posted July 26, 2013 at 09:04 AM Author Report #520041 Posted July 26, 2013 at 09:04 AM Faz debug com um breakpoint nessa linha. Selecciona o texto "GridView1.Columns", clica com o botão direito e faz "QuickWatch...". Ai consegues ver o conteúdo da variavel e ver se tem colunas. Não está a receber nada.
nelsonr Posted July 26, 2013 at 09:07 AM Report #520042 Posted July 26, 2013 at 09:07 AM O que queres dizer com isso? Não te aparece nada no QuickWatch? Ou aparece que não tem colunas?
startuga Posted July 26, 2013 at 09:10 AM Author Report #520043 Posted July 26, 2013 at 09:10 AM O que queres dizer com isso? Não te aparece nada no QuickWatch? Ou aparece que não tem colunas? Aparece que não tem colunas.
nelsonr Posted July 26, 2013 at 09:17 AM Report #520044 Posted July 26, 2013 at 09:17 AM Pois, era o que desconfiava. Como é que estás a criar a grelha?
startuga Posted July 26, 2013 at 09:25 AM Author Report #520045 Posted July 26, 2013 at 09:25 AM Pois, era o que desconfiava. Como é que estás a criar a grelha? Desta forma, passo a citar o código: If Not IsPostBack Then 'Sql Connect to the xxxxx database Dim strPath As String = Server.MapPath("~\app_data\xxxxx.mdf") strConnectionString = "Data Source=xxxxxxx;Initial Catalog=xxxxxx;Integrated Security=True" Dim strCommand As String = "SELECT HPedidos.Pais,DATEPART(hh, HPedPart_Surtido.Fecha) Hora, HPedPart_Surtido.ID_Estacion, SUM(HPedPart_Surtido.Cantidad_Surtida) AS TotalSetsPicked FROM HPedPart_Surtido INNER JOIN HPedidos ON HPedPart_Surtido.ID_Pedido = HPedidos.ID WHERE (DATEPART(dd, HPedPart_Surtido.Fecha) = DATEPART(dd, GETDATE())) AND (DATEPART(mm, HPedPart_Surtido.Fecha) = DATEPART(mm, GETDATE())) AND (DATEPART(yyyy, HPedPart_Surtido.Fecha) = DATEPART(yyyy, GETDATE())) GROUP BY HPedidos.Pais,DATEPART(hh, HPedPart_Surtido.Fecha), HPedPart_Surtido.ID_Estacion order BY DATEPART(hh, HPedPart_Surtido.Fecha) desc, HPedidos.Pais, HPedPart_Surtido.ID_Estacion " Dim conn As New SqlConnection(strConnectionString) Dim sqlcommand As New SqlCommand(strCommand, conn) Dim drDataReader As SqlDataReader Dim dtDataTable As New DataTable conn.Open() drDataReader = sqlcommand.ExecuteReader dtDataTable.Load(drDataReader) GridView1.DataSource = dtDataTable GridView1.DataBind() conn.Close() End If
nelsonr Posted July 26, 2013 at 09:29 AM Report #520047 Posted July 26, 2013 at 09:29 AM E estavas a colocar o codigo de alterar o titulo onde? Experimentaste por exemplo logo ai depois do databind?
startuga Posted July 26, 2013 at 09:40 AM Author Report #520048 Posted July 26, 2013 at 09:40 AM E estavas a colocar o codigo de alterar o titulo onde? Experimentaste por exemplo logo ai depois do databind? Exprimentei em vários locais, antes de abrir a ligação, depois da ligação já feita, e mesmo no fim da ligação fechada.
startuga Posted July 26, 2013 at 01:38 PM Author Report #520074 Posted July 26, 2013 at 01:38 PM Obrigado pela ajuda pessoal, acabei por solucionar o problema utilizando o evento RowCreated da seguinte forma: Private Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated If (e.Row.RowType = DataControlRowType.Header) Then e.Row.Cells(0).Text = "País" e.Row.Cells(1).Text = "Hora" e.Row.Cells(2).Text = "Estação" e.Row.Cells(3).Text = "Local" End If End Sub
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now