Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there!
I have a problem with my website. I open a new page in Fancybox and add records. When I close or update, the gridview back but despite adding the datatable (contains all the records) and databind, screen no updates records.

XML
<asp:GridView ID="gridPedido" runat="server" CssClass="miGrid" AutoGenerateColumns="false" DataKeyNames="CodProducto,Variante"
            onrowdeleting="gridPedido_RowDeleting" onrowcommand="gridPedido_RowCommand" OnSelectedIndexChanged="gridPedido_SelectedIndexChanged"  >
                <Columns>
                    <asp:BoundField DataField="Pedido" HeaderText="Pedido" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ReadOnly="true" />
                    <asp:BoundField DataField="Linea" HeaderText="Linea" ItemStyle-HorizontalAlign="Left" ReadOnly="true" />
                    <asp:BoundField DataField="CodProducto" HeaderText="Tipo Contenedor" />
                    <asp:BoundField DataField="Producto" HeaderText="Tipo" ItemStyle-HorizontalAlign="Left" ReadOnly="true" />
                    <asp:BoundField DataField="Variante" HeaderText="Variante" ItemStyle-HorizontalAlign="Center" ReadOnly="true"  />
                    <asp:BoundField DataField="Servicio" HeaderText="Servicio" ItemStyle-HorizontalAlign="Center" ReadOnly="true" />
                    <asp:CommandField ShowEditButton="false" EditText="Editar" UpdateText="Aceptar"
                    CancelText="Cancelar" DeleteText="Borrar" ButtonType="Image"
                    CancelImageUrl="~/resources/images/cancelar.png" EditImageUrl="~/resources/images/modificar.png"
                        ShowSelectButton="true" SelectText="Seleccionar" SelectImageUrl="~/resources/images/modificar.png"
                    UpdateImageUrl="~/resources/images/aceptar.png" ShowDeleteButton="true"  DeleteImageUrl ="~/resources/images/basura.png"/>
                    <asp:ButtonField Text="Añadir contenido" ImageUrl="~/resources/images/add.png" CommandName="AñadirContenido" ButtonType="Image" />
                </Columns>
                <EmptyDataTemplate>
                <div style="text-align:center">No se han encontrado elementos</div>
                </EmptyDataTemplate>
            </asp:GridView>


C#
protected void ActualizarGrid()
{
    DataTable dtlineas = f.ObtenerLineasPedidoWeb(Session["Pedido"].ToString());
    ViewState["Lineas"] = dtlineas;

    gridPedido.DataSource = null;
    gridPedido.DataBind();
    gridPedido.DataSource = dtlineas;
    gridPedido.DataBind();

    if (gridPedido.Rows.Count > 0)
    {
        pnl_Pedido.Visible = true;
    }
}
Posted
Comments
SRK90 7-Aug-14 3:11am    
make sure the dtlineas is getting the Datatable value's. If that is null, then grid view will be empty.
Ana Valero 7-Aug-14 9:04am    
Datatable is full. Have the correct data, but in screen dont't refresh it.

1 solution

DataTable dtlineas = f.ObtenerLineasPedidoWeb(Session["Pedido"].ToString());
gridPedido.DataSource = dtlineas;
gridPedido.DataBind();


Use the above codes alone and check whether the dtlineas datatable has the updated records by inserting debugger.
 
Share this answer
 
Comments
Ana Valero 7-Aug-14 3:49am    
The data are reviewed and are correct but don't put them in the gridview
Strikerzz Arut 7-Aug-14 4:49am    
Set viewstatemode="Disabled in ur gridview and try it.
Ana Valero 7-Aug-14 6:28am    
I still having the same problem. It doesn't work for me. I think if it's possible that when I come back from fancybox, lost the instance or something similar? If I add some item to gridview with other button, it charges data correctly, included data before no updated
Strikerzz Arut 7-Aug-14 6:49am    
Please check whether ur gridPedido's Data source was updated as per ur changes. Your updated value is not in the data source and so its happening.
DataTable dtlineas = f.ObtenerLineasPedidoWeb(Session["Pedido"].ToString()); check this line while debugging.

Ana Valero 7-Aug-14 9:04am    
Datatable is full. Have the correct data, but in screen dont't refresh it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900