locked
DGV doesn't refresh RRS feed

  • Question

  • User-1847850515 posted

    Hi Guys,

    I explain my problem. I have an aspx page "GestionDisposV2.aspx" with a gridview "DGV_LISTEJOURS" and a iframe "FR_MODIFPERIODE".

    My frame is dynamic with other aspx pages.

    In pages which are in the frame i have buttons which update a database And, at the end or working i want to refresh gridview

    Code which call an example of page in frame

    FR_MODIFPERIODE.Attributes["src"] = "ModifPeriode_Heures.aspx?date="+ xligne.Cells[2].Text + " (Id:" + xligne.Cells[1].Text + ")&Debut="+ xligne.Cells[3].Text+"&Fin="+ xligne.Cells[4].Text;

    In button which make update in database i have this code

    GestionDisposV2.refreshdgvext(xidperiode);

    GestionDisposV2 is the page who have the gridview and the iframe

    this is the code of the refresh

    public static void refreshdgvext(int xidperiode)
            {
                DataTable xdttempo = new DataTable();
                DataRow xlignedttempo = null;
                GridView xdgv = (GridView)xpage.FindControl("DGV_LISTEJOURS");
                //on rempli la table des jours depuis la table
                DataTable xlistedispo_jours = BibliothequeClasses.GestionBDD.LectureBdd("select * from bddispos_periodesjours where idbddispos_periodes_int = '" + xidperiode + "';", BibliothequeClasses.Variables.xretourbddsiok);
                xdttempo.Columns.Add(new DataColumn("AMPOULE", typeof(string)));
                xdttempo.Columns.Add(new DataColumn("ID", typeof(string)));
                xdttempo.Columns.Add(new DataColumn("JOUR", typeof(string)));
                xdttempo.Columns.Add(new DataColumn("DEBUTDISPO", typeof(string)));
                xdttempo.Columns.Add(new DataColumn("FINDISPO", typeof(string)));
                xdttempo.Columns.Add(new DataColumn("BTNACTIVER", typeof(string)));
                DateTime xjour;
    
                //stockage dans la dt tempo
                foreach (DataRow xdispo_jours in xlistedispo_jours.Rows)
                {
                    xjour = DateTime.Parse(xdispo_jours["dateperiode_da"].ToString());
                    xlignedttempo = xdttempo.NewRow();
                    if (int.Parse(xdispo_jours["dateperiode_actif_bo"].ToString()) == 1)
                    {
                        xlignedttempo["AMPOULE"] = "~/Images/icones/icons8-lumière-allumée-48.png";
                        xlignedttempo["BTNACTIVER"] = "Desactiver";
                    }
                    else
                    {
                        xlignedttempo["AMPOULE"] = "~/Images/icones/icons8-lumière-éteinte-48.png";
                        xlignedttempo["BTNACTIVER"] = "Activer";
                    }
                    xlignedttempo["ID"] = int.Parse(xdispo_jours["idbddispos_periodesjours_int"].ToString());
                    xlignedttempo["JOUR"] = BibliothequeClasses.GestionDate_Heure.jour_jour_date(xjour) + "/" + BibliothequeClasses.GestionDate_Heure.mois_jour_date(xjour) + "/" + BibliothequeClasses.GestionDate_Heure.annee_jour_date(xjour);
                    xlignedttempo["DEBUTDISPO"] = xdispo_jours["heuredebut_vc"].ToString();
                    xlignedttempo["FINDISPO"] = xdispo_jours["heurefin_vc"].ToString();
                    xdttempo.Rows.Add(xlignedttempo);
                }
                //deversement dans la dgv
                xdgv.DataSource = xdttempo;
                xdgv.DataBind();
            }

    the "xpage" is in load of GestionDisposV2

    public static Page xpage;
    xpage = this.Page;

    My problem, GridView Doesn't refresh, do you have an idea of why?

    Sorry for my english, it isn't my native language.

    Thanks you for helping, this is 5 days i search and don't find a solution

    Tuesday, June 11, 2019 6:06 AM

All replies

  • User288213138 posted

    Hi AmethysteDev,

    AmethysteDev

    GridView Doesn't refresh

    According to your description, I tried to reproduce your problem, but found that some code is missing.

    If you want refresh the content of GridView by editting code in code behind,the page must be refreshed after you click button.

    So you can check if your page is refreshed after you click the button. If the page is refreshed, you can debug your page to find the problem.

    If you haven't solved your problem yet, please post you aspx and aspx.cs code.

    Best regards,

    Sam

    Wednesday, June 12, 2019 9:25 AM
  • User-1847850515 posted

    Hi Samvu,

    Thanks for trying to helping me.

    To start, i understand that some code are missing, cause, there's classes in my code (classes to manage database or to manage days/hours. So if, you don't have classes, you'll have code missing.

    I tried to put an stop point after, the refresh and i don't go to the stop point, so i suppose the page d'ont refresh.

    To give you an idea of my code, this is the code for the GestionDisposV2.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GestionDisposV2.aspx.cs" Inherits="formhome.GestionDisposV2" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
        <link id="cssbase" rel="stylesheet" type="text/css" runat="server"/>
        <link id="csspage" rel="stylesheet" type="text/css" runat="server"/>
        <style type="text/css">
            .auto-style1 {
                height: 200px;
            }
            .auto-style2 {
                height: 168px;
            }
        </style>
        </head>
    <body>
        <form id="form1" runat="server">
            <div id="periodesdispos">
                <asp:Label ID="Label1" runat="server" Text="Mes Periodes de Dispo" Font-Size="X-Large" CssClass="texte-gauche"></asp:Label>
                <br />
                <asp:GridView ID="DGV_PERIODES" runat="server" AutoGenerateColumns="False" OnRowCommand="DGV_PERIODES_RowCommand" OnRowDataBound="DGV_PERIODES_RowDataBound">
                    <Columns>
                        <asp:ButtonField ButtonType="Button" CommandName="modifier" Text="Modifier" />
                        <asp:ButtonField ButtonType="Button" CommandName="supprimer" Text="Supprimer" />
                        <asp:BoundField DataField="ID" HeaderText="ID" />
                        <asp:BoundField DataField="debut" HeaderText="DEBUT" />
                        <asp:BoundField DataField="fin" HeaderText="FIN" />
                    </Columns>
                </asp:GridView>
            </div>
            <div id="paramperiodes">
                <asp:Label ID="Label2" runat="server" Text="Detail / Paramétrage des Périodes" Font-Size="X-Large" CssClass="texte-droit"></asp:Label>
                <br />
                <p>
                    <asp:Label ID="Label3" runat="server" Text="Debut Periode" Width="110px" CssClass="texte-droit"></asp:Label>
                    <asp:Label ID="Label4" runat="server" Text="Fin Periode" Width="150px" CssClass="texte-droit"></asp:Label>
                    <br />
                    <asp:TextBox ID="TB_DEBUTPERIODE" runat="server" ReadOnly="True"></asp:TextBox>
                    <asp:ImageButton ID="IMGBTN_DEBUTPERIODE" runat="server" Height="20px" ImageUrl="~/Images/icones/icons8-calendrier-48.png" Width="20px" OnClick="BTN_CAL_Click" />
                    <asp:TextBox ID="TB_FINPERIODE" runat="server" ReadOnly="True"></asp:TextBox>
                    <asp:ImageButton ID="IMGBTN_FINPERIODE" runat="server" Height="20px" ImageUrl="~/Images/icones/icons8-calendrier-48.png" Width="20px" OnClick="BTN_CAL_Click" />
                </p>
                    <asp:Panel ID="PAN_CALENDRIER" runat="server" HorizontalAlign="center" Visible="False">
                        <asp:Calendar ID="CAL_CAL" runat="server" BackColor="White" BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest" FirstDayOfWeek="Monday" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="90px" OnSelectionChanged="CAL_CAL_SelectionChanged" Width="90px">
                            <DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
                            <NextPrevStyle VerticalAlign="Bottom" />
                            <OtherMonthDayStyle ForeColor="#808080" />
                            <SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
                            <SelectorStyle BackColor="#CCCCCC" />
                            <TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
                            <TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
                            <WeekendDayStyle BackColor="#FFFFCC" />
                        </asp:Calendar>
                    </asp:Panel>
                <p> 
                    <asp:Label ID="Label5" runat="server" Text="Heure Deb Dispo" Width="152px" CssClass="texte-droit"></asp:Label>
                    <asp:Label ID="Label6" runat="server" Text="Heure Fin Dispo" Width="150px" CssClass="texte-droit"></asp:Label>
                    <br />
                    <asp:TextBox ID="TB_HEUREDEBDISPO_GEN" runat="server"></asp:TextBox>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:TextBox ID="TB_HEUREFINDISPO_GEN" runat="server"></asp:TextBox>
                </p>
                <asp:Panel ID="Panel1" runat="server" HorizontalAlign="Center">
                <ul>
                    <li><asp:CheckBox ID="CHB_LUNDI" runat="server" Text="Lundi" TextAlign="Left" /></li>
                    <li><asp:CheckBox ID="CHB_MARDI" runat="server" Text="Mardi" TextAlign="Left" /></li>
                    <li><asp:CheckBox ID="CHB_MERCREDI" runat="server" Text="Mercredi" TextAlign="Left" /></li>
                    <li><asp:CheckBox ID="CHB_JEUDI" runat="server" Text="Jeudi" TextAlign="Left" /></li>
                    <li><asp:CheckBox ID="CHB_VENDREDI" runat="server" Text="Vendredi" TextAlign="Left" /></li>
                    <li><asp:CheckBox ID="CHB_SAMEDI" runat="server" Text="Samedi" TextAlign="Left" /></li>
                    <li><asp:CheckBox ID="CHB_DIMANCHE" runat="server" Text="Dimanche" TextAlign="Left" /></li>
                </ul>
                <br />
                <asp:Button ID="BTN_MAJ" runat="server" Text="MAJ" OnClick="BTN_MAJ_Click" CssClass="bouton" />
                    <br />
                    <br />
                    <div id="listejours">
                         <asp:GridView ID="DGV_LISTEJOURS" runat="server" AutoGenerateColumns="False" OnRowCommand="DGV_LISTEJOURS_RowCommand" OnRowDataBound="DGV_LISTEJOURS_RowDataBound">
                            <Columns>
                                <asp:ImageField DataImageUrlField="AMPOULE"></asp:ImageField>
                                <asp:BoundField DataField="ID" HeaderText="ID" />
                                <asp:BoundField DataField="JOUR" HeaderText="JOUR" />
                                <asp:BoundField DataField="DEBUTDISPO" HeaderText="DEBUT DISPO" />
                                <asp:BoundField DataField="FINDISPO" HeaderText="FIN DISPO" />
                                <asp:ButtonField ButtonType="Button" CommandName="ajoutdispo" Text="+" />
                                <asp:ButtonField ButtonType="Button" CommandName="modifier" Text="Modifier" />
                                <asp:ButtonField ButtonType="Button" CommandName="activer" Text="ACTIVER" DataTextField="BTNACTIVER" />
                            </Columns>
                        </asp:GridView>
                    </div>
                    <div id="paramjour" class="auto-style1">
                        <br />
                        <iframe id="FR_MODIFPERIODE" runat="server" class="auto-style2"/>
                    </div>
                    <div id="creerperiode">
                        <br />
                        <asp:Button ID="BTN_CREERPERIODE" runat="server" Text="Creer Periode" CommandArgument="creer" OnCommand="BTN_CREERPERIODE_Command" CssClass="bouton" />
                    </div>
                </asp:Panel>
            </div>
            <div id="retour">
                <asp:Panel ID="PAN_RETOUR" runat="server" Visible="False">
                    <asp:Label ID="LBL_RETOUR" runat="server" Text="Label" ForeColor="Red"></asp:Label>
                </asp:Panel>
            </div>
        </form>
    </body>
    </html>

    I have this code to manage DGV_LISTEJOURS

     protected void DGV_LISTEJOURS_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                GridViewRow xligne = DGV_LISTEJOURS.Rows[Convert.ToInt32(e.CommandArgument)]; //la row de la ligne ou il a cliqué
                switch (e.CommandName)
                {
                    case "ajoutdispo":
                        Response.Write("<script>alert('Bientôt Disponible')</script>");
                        break;
                    case "modifier":
                        //affichage de la frame modif heures
                        FR_MODIFPERIODE.Attributes["src"] = "ModifPeriode_Heures.aspx?date="+ xligne.Cells[2].Text + " (Id:" + xligne.Cells[1].Text + ")&Debut="+ xligne.Cells[3].Text+"&Fin="+ xligne.Cells[4].Text;
                        break;
                    case "activer":
                        //on va chercher l'etat du jour
                        int xetat = 0;
                        DataTable xretour = new DataTable();
                        xretour = BibliothequeClasses.GestionBDD.LectureBdd("select dateperiode_actif_bo from bddispos_periodesjours where idbddispos_periodesjours_int = '" + int.Parse(xligne.Cells[1].Text) + "';", BibliothequeClasses.Variables.xretourbddsiok);
                        xetat = int.Parse(xretour.Rows[0]["dateperiode_actif_bo"].ToString());
                        //on ouvre l'iframe avec les paramétres
                        FR_MODIFPERIODE.Attributes["src"] = "ModifPeriode_ActivationJour.aspx?idjour="+ xligne.Cells[1].Text;
                        break;
                }
            }

    so when i click on "modifier" i open "ModifPeriode_Heures.aspx" with parameters in "FR_MODIFPERIODE"

    this is the code for page "ModifPeriode_Heures.aspx"

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ModifPeriode_Heures.aspx.cs" Inherits="formhome.ModifPeriode_Heures" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                 <asp:Label ID="LBL_DATEJOUR_PARAM" runat="server"></asp:Label>
                 <br />
                 <asp:Label ID="Label7" runat="server" Text="Heure Deb Dispo"></asp:Label>
                 <br />
                 <asp:TextBox ID="TB_HEUREDEB_DISPO" runat="server"></asp:TextBox>
                 <br />
                 <asp:Label ID="Label8" runat="server" Text="Heure Fin Dispo"></asp:Label>
                 <br />
                 <asp:TextBox ID="TB_HEUREFIN_DISPO" runat="server"></asp:TextBox>
                 <br />
                 <br />
                 <asp:Button ID="BTN_VALID_HEURE_DISPO" runat="server" Text="Valider" OnClick="BTN_VALID_HEURE_DISPO_Click" />
            </div>
        </form>
    </body>
    </html>
    

    Problem is "BTN_VALID", when i click on it i launch update on database then refresh GridView on first page

    this is the code

    protected void BTN_VALID_HEURE_DISPO_Click(object sender, EventArgs e)
            {
                int xidperiode = int.Parse(BibliothequeClasses.GestionBDD.LectureBdd("select idbddispos_periodes_int from bddispos_periodesjours where idbddispos_periodesjours_int = '"+ int.Parse(LBL_DATEJOUR_PARAM.Text.Substring(15, LBL_DATEJOUR_PARAM.Text.Length - 16)) + "';",BibliothequeClasses.Variables.xretourbddsiok).Rows[0]["idbddispos_periodes_int"].ToString());
                //on verifie si les deux heures sont remplies et que le debut est avant la fin
                if (BibliothequeClasses.GestionDate_Heure.controlemasqueheures(TB_HEUREDEB_DISPO.Text) && BibliothequeClasses.GestionDate_Heure.controlemasqueheures(TB_HEUREFIN_DISPO.Text))
                {
                    if (BibliothequeClasses.GestionDate_Heure.controleheuredebutfin(TB_HEUREDEB_DISPO.Text, TB_HEUREFIN_DISPO.Text))//on controle si l'heure de debut est bien inferieure a l'heure de fin
                    {
                        Boolean xmodifok = true; ;
                        //on verifie s'il y a des rdv sur l'ancienne plage horaire qui ne seraient pas compatible avec la nouvelle plage horaire
                        DataTable xretourrdv = BibliothequeClasses.GestionBDD.LectureBdd("select * from bdrdv where idbddispos_periodesjours_int = '" + int.Parse(LBL_DATEJOUR_PARAM.Text.Substring(15, LBL_DATEJOUR_PARAM.Text.Length - 16)) + "'", BibliothequeClasses.Variables.xretourbddsiok);
                        foreach (DataRow xrdv in xretourrdv.Rows)
                        {
                            //pour chaque rdv de ce jour là, on recupere les heures de début et de fin du rdv
                            string xhdeb = xrdv["heuredebut_vc"].ToString();
                            string xhfin = xrdv["heurefin_vc"].ToString();
                            xmodifok = true;
                            //on verifie si l'heure de début du rdv est inferieure à la nouvelle heure de début ou si l'heure de fin du rdv est supérieure à la nouvelle heure de fin
                            if (BibliothequeClasses.GestionDate_Heure.controleheuredebutfin(TB_HEUREDEB_DISPO.Text, xhdeb) && BibliothequeClasses.GestionDate_Heure.controleheuredebutfin(xhfin, TB_HEUREFIN_DISPO.Text))
                            {//on est bon, pas de rdv qui depassent
                            }
                            else
                            {//modification impossible, on informe l'utilisateur et on interdit la modification
                                xmodifok = false;
                                GestionDisposV2.refreshretour("Les nouvelles heures sont impossibles, il y a des rdv en dehors de ce créneau horaire");
                            }
                        }
                        if (xmodifok)
                        {
                            //on update la base avec les nouvelles heures
                            string xretour = BibliothequeClasses.GestionBDD.EcritureBDD("update bddispos_periodesjours set heuredebut_vc = '" + TB_HEUREDEB_DISPO.Text + "', heurefin_vc = '" + TB_HEUREFIN_DISPO.Text + "' where idbddispos_periodesjours_int = '" + int.Parse(LBL_DATEJOUR_PARAM.Text.Substring(15, LBL_DATEJOUR_PARAM.Text.Length - 16)) + "';", BibliothequeClasses.Variables.xretourbddsiok);
                            if (xretour == BibliothequeClasses.Variables.xretourbddsiok)
                            {//update bdd ok, //on recupere l'id periode
                                DataTable xretouridperiode = BibliothequeClasses.GestionBDD.LectureBdd("select idbddispos_periodes_int from bddispos_periodesjours where idbddispos_periodesjours_int = '" + int.Parse(LBL_DATEJOUR_PARAM.Text.Substring(15, LBL_DATEJOUR_PARAM.Text.Length - 16)) + "';", BibliothequeClasses.Variables.xretourbddsiok);
                                //on reload le dgv
                                GestionDisposV2.refreshdgvext(xidperiode);
                            }
                            else
                            {//update pas ok, on informe l'utilisateur
                                GestionDisposV2.refreshretour("Une erreur s'est produite lors de la mise à jour des heures : " + xretour);
                            }
                        }
                    }
                    else
                    {
                        GestionDisposV2.refreshretour("Les heures ne sont pas valides");
                    }
                }
                else
                {
                    GestionDisposV2.refreshretour("Les heures doivent etre au format HH:MM");
                }
            }

    and more exactly the part with problem

    //on update la base avec les nouvelles heures
                            string xretour = BibliothequeClasses.GestionBDD.EcritureBDD("update bddispos_periodesjours set heuredebut_vc = '" + TB_HEUREDEB_DISPO.Text + "', heurefin_vc = '" + TB_HEUREFIN_DISPO.Text + "' where idbddispos_periodesjours_int = '" + int.Parse(LBL_DATEJOUR_PARAM.Text.Substring(15, LBL_DATEJOUR_PARAM.Text.Length - 16)) + "';", BibliothequeClasses.Variables.xretourbddsiok);
                            if (xretour == BibliothequeClasses.Variables.xretourbddsiok)
                            {//update bdd ok, //on recupere l'id periode
                                DataTable xretouridperiode = BibliothequeClasses.GestionBDD.LectureBdd("select idbddispos_periodes_int from bddispos_periodesjours where idbddispos_periodesjours_int = '" + int.Parse(LBL_DATEJOUR_PARAM.Text.Substring(15, LBL_DATEJOUR_PARAM.Text.Length - 16)) + "';", BibliothequeClasses.Variables.xretourbddsiok);
                                //on reload le dgv
                                GestionDisposV2.refreshdgvext(xidperiode);

    you see, i call a class on first page and gridview don't reload.

    If you have discord i can explain you more with share screen

    Many thanks for your help

    Thursday, June 13, 2019 12:15 PM
  • User288213138 posted

    Hi AmethysteDev,

    I am very sorry, I still can't reproduce your question, because I don't know what BibliothequeClasses is doing in your code.

    Please post the code about BibliothequeClasses in your code.

    Best Regards,

    Sam

    Wednesday, June 19, 2019 10:26 AM