locked
2 gridviews appear on page, First gridview never gets overwritten. RRS feed

  • Question

  • User799222684 posted

    When Page first loads, 1 gridview saying "no records found" is correct.

    I push a button in page and I get a gridview to appear saying "no records found". This part is correct.

    However, At the bottom of the same page, the "no records found" still appears when page first loaded.

    It appears I cannot clear/ overwrite my gridview from when the page first loads.

    The one with the oldest time( 14.336)  is the one that I cannot overwrite.

    I do NOT want to reload entire page. I am using an updatepanel for the gridview.

    What can I do to eliminate/ Overwrite the first gridview ?

    two gridviews

    ---  View page source below. There is only ONE "no records found" ---- 
    <div id="Div1" class="grid5wrapper">
    
                  <div class="box_tr box_allrow">
                    <p>ENVIRONMENT</p>
    
                </div>
                        </div>
                <div id="rowbtnkey16" class="grid5wrapper">
                <div class="box_tr boxleft">
                    <div id="divbtnkey16" style="display:block; width:100%;">
                    <input type="submit" name="btnkey16" value="X-Consistent Moisture" onclick="togglestyle(this);" id="btnkey16" class="btnon" />
                    </div>
               </div>
                <div class="box_tr boxmiddle">
                    <div id="divbtnkey17" style="display:block; width:100%;">
                    <input type="submit" name="btnkey17" value="X-Partial Sun" onclick="togglestyle(this);" id="btnkey17" class="btnon" />
                    </div>
                </div>
                <div class="box_tr boxright"> 
                    <div id="divbtnkey18" style="display:none;width:100%;">
                    <input type="submit" name="btnkey18" value="Label" onclick="togglestyle(this);" id="btnkey18" class="btnon" />
                    </div>
                </div>
                 </div>
                <div id="rowbtnkey19" class="grid5wrapper" style="display:none;">
                <div class="box_tr boxleft">
                    <div id="divbtnkey19" style="display:none;width:100%;">
                    <input type="submit" name="btnkey19" value="Label" onclick="togglestyle(this);" id="btnkey19" class="btnon" />
                    </div>
               </div>
                <div class="box_tr boxmiddle">
                    <div id="divbtnkey20" style="display:none;width:100%;">
                    <input type="submit" name="btnkey20" value="Label" onclick="togglestyle(this);" id="btnkey20" class="btnon" />
                    </div>
                </div>
                <div class="box_tr boxright"> 
                    <div id="divbtnkey21" style="display:none;width:100%;">
                    <input type="submit" name="btnkey21" value="Label" onclick="togglestyle(this);" id="btnkey21" class="btnon" />
                    </div>
                </div>
                 </div>
    
                <div id="rowbtnkey22" class="grid5wrapper" style="display:none;">
                <div class="box_tr boxleft">
                    <div id="divbtnkey22" style="display:none;width:100%;">
                    <input type="submit" name="btnkey22" value="Label" onclick="togglestyle(this);" id="btnkey22" class="btnon" />
                    </div>
               </div>
                <div class="box_tr boxmiddle">
                    <div id="divbtnkey23" style="display:none;width:100%;">
                    <input type="submit" name="btnkey23" value="Label" onclick="togglestyle(this);" id="btnkey23" class="btnon" />
                    </div>
                </div>
                <div class="box_tr boxright"> 
                    <div id="divbtnkey24" style="display:none;width:100%;">
                    <input type="submit" name="btnkey24" value="Label" onclick="togglestyle(this);" id="btnkey24" class="btnon" />
                    </div>
                </div>
                 </div>
                <div id="rowbtnkey25" class="grid5wrapper">
                <div class="box_tr boxleft">
                    <div id="divbtnkey25" style="display:none;width:100%;">
                    <input type="submit" name="btnkey25" value="Label" onclick="togglestyle(this);" id="btnkey25" class="btnon" />
                    </div>
               </div>
                <div class="box_tr boxmiddle">
                    <div id="divbtnkey26" style="display:none;width:100%;">
                    <input type="submit" name="btnkey26" value="Label" onclick="togglestyle(this);" id="btnkey26" class="btnon" />
                    </div>
                </div>
                <div class="box_tr boxright"> 
                    <div id="divbtnkey27" style="display:none;width:100%;">
                    <input type="submit" name="btnkey27" value="Label" onclick="togglestyle(this);" id="btnkey27" class="btnon" />
                    </div>
                </div>
                 </div>
            </div>
                    <div class="div_ZZZZgrid_photo">
                <div>
    		<table class="css_grid_photo" cellspacing="0" align="Center" id="GridView1" style="border-style:None;width:90%;border-collapse:collapse;">
    			<tr>
    				<th class="csshdr_info" scope="col">Common/ Scientific Name</th><th scope="col">&nbsp;</th>
    			</tr><tr style="background-color:Gainsboro;">
    				<td class="cssmin_days">
                                <div class="gr1_listplants">
                                    <div class="box_a_flex">
                                        <div class="common_a">
                                            No Records found. 2019-07-19 10:07:32.485
                                        </div>
                                        <div class="common_b">
                                             
                                        </div>
                                     </div>
                                </div>
                            </td><td class="css_tdphoto_days">
                            </td>
    			</tr>
    		</table>
    	</div>
                        </div>
           
    

    below is snippet code behind

                        using (OracleCommand cmd = new OracleCommand(updateQuery, conn))
                        {
                            cmd.Parameters.Add(new OracleParameter("menu_id", strmpmenu_id));
                            OracleDataAdapter daa = new OracleDataAdapter(cmd);
                            intRecordCount = daa.Fill(dtt);
                            if (intRecordCount == 0)
                            {
                                string timestamp = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff",
                                                CultureInfo.InvariantCulture);
                                DataRow ddr = dtt.NewRow();
                                ddr["COMMON_NAME"] = "No Records found. "+ timestamp.ToString();
                                ddr["SCIENTIFIC_NAME"] = "";
                                ddr["ID"] = "0";
                                ddr["IMAGES_1"] = "";
                                ddr["IMAGES_2"] = "";
                                ddr["IMAGES_3"] = "";
                                ddr["IMAGES_4"] = "";
                                ddr["IMAGES_5"] = "";
                                ddr["IMAGES_6"] = "";
                                ddr["IMAGES_7"] = "";
                                ddr["IMAGES_8"] = "";
                                ddr["IMAGES_9"] = "";
    
                                dtt.Rows.Add(ddr);
                            }
                            GridView1.DataSource = dtt;
                            GridView1.DataBind();
                            conn.Close();
                        }
    

    Below is snippet of aspx code

            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    
                <ContentTemplate>
    
         [....]
                <asp:GridView ID="GridView1" runat="server" 
                    PagerStyle-CssClass="css_grid_pager" OnPageIndexChanging="GridView1_PageIndexChanging"   width="90%" AutoGenerateColumns="False"  AllowPaging="True" HorizontalAlign="Center" CssClass="css_grid_photo" PagerStyle-HorizontalAlign="Center"
                    BorderStyle="None"
                     OnRowDataBound="GridView1_RowDataBound" GridLines="None">
                    
                     <RowStyle BackColor="#dcdcdc" />
                     <AlternatingRowStyle BackColor="White" />
    
                    <Columns>
    
                        <asp:TemplateField HeaderText="Common/ Scientific Name" ControlStyle-CssClass="cssmin_days" FooterStyle-CssClass="div_grid_2photo" HeaderStyle-CssClass="csshdr_info" ItemStyle-CssClass="cssmin_days">
                            <ItemTemplate>
                                <div class="gr1_listplants">
                                    <div class="box_a_flex">
                                        <div class="common_a">
                                            <%# Eval("COMMON_NAME")%>
                                        </div>
                                        <div class="common_b">
                                             <%# Eval("SCIENTIFIC_NAME")%>
                                        </div>
                                     </div>
                                </div>
    
    
    
    
    
                            </ItemTemplate>
                            </asp:TemplateField>
    
    
                        
    
                        <asp:TemplateField HeaderText="" ControlStyle-CssClass="css_tdphoto_days" ItemStyle-CssClass="css_tdphoto_days" >
                            <ItemTemplate>
                            <asp:PlaceHolder ID="columnPlaceHolder" runat="server"></asp:PlaceHolder>
    
    
                            </ItemTemplate>
    
                        </asp:TemplateField>
    
                    </Columns>
                    <PagerStyle ForeColor="Black" HorizontalAlign="Center" />
    
    
    
                </asp:GridView>
    
                </ContentTemplate>
    
            </asp:UpdatePanel>
    
    

    Friday, July 19, 2019 10:55 AM

All replies

  • User839733648 posted

    Hi sh,

    According to your description, I'm sorry that I could not reproduce your issue successfully.

    Your screenshot is broken, so I'm not clear about what your page dispaly like.

    I'm confused about your requirement, in a gridview, if it could find the data from database, it will show correctly.

    If it do not find any datas, you could set it as "no records found".

    I push a button in page and I get a gridview to appear saying "no records found". This part is correct.

    However, At the bottom of the same page, the "no records found" still appears when page first loaded.

    Could you please share the button's click event ? I think this may be related to the result.

    Besides, I've made a test according to your code on my side and it works well.

    I've created a search button to test if the "no records found" could appear.

    My database is SQL Server but the way of operating the database is similar to Oracle.

    I hope this will be helpful to you.

    .aspx

        <form id="form1" runat="server">
            <div class="div_ZZZZgrid_photo">
                <div>
                    Search:
                    <asp:TextBox ID="txtSearch" runat="server" />
                    <asp:Button Text="Search" runat="server" OnClick="Search_Click" />
                    <hr />
                    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <asp:GridView ID="GridView1" runat="server"
                                PagerStyle-CssClass="css_grid_pager" OnPageIndexChanging="GridView1_PageIndexChanging" Width="90%" AutoGenerateColumns="False" AllowPaging="True" HorizontalAlign="Center" CssClass="css_grid_photo" PagerStyle-HorizontalAlign="Center"
                                BorderStyle="None" GridLines="None">
                                <RowStyle BackColor="#dcdcdc" />
                                <AlternatingRowStyle BackColor="White" />
                                <Columns>
                                    <asp:TemplateField HeaderText="Common/ Scientific Name" ControlStyle-CssClass="cssmin_days" FooterStyle-CssClass="div_grid_2photo" HeaderStyle-CssClass="csshdr_info" ItemStyle-CssClass="cssmin_days">
                                        <ItemTemplate>
                                            <div class="gr1_listplants">
                                                <div class="box_a_flex">
                                                    <div class="common_a">
                                                        <%# Eval("Eid")%>
                                                    </div>
                                                    <div class="common_b">
                                                        <%# Eval("Ename")%>
                                                    </div>
                                                </div>
                                            </div>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="" ControlStyle-CssClass="css_tdphoto_days" ItemStyle-CssClass="css_tdphoto_days">
                                        <ItemTemplate>
                                            <asp:PlaceHolder ID="columnPlaceHolder" runat="server"></asp:PlaceHolder>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                                <PagerStyle ForeColor="Black" HorizontalAlign="Center" />
                            </asp:GridView>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </div>
            </div>
        </form>

    code behind

           protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    BindData();
                }
            }
            string constr = ConfigurationManager.ConnectionStrings["EmployeeManagementConnectionString"].ConnectionString;
            private void BindData()
            {
                SqlConnection con = new SqlConnection(constr);
                string myquery = "SELECT Eid, Ename FROM tb_info WHERE Ename LIKE '%' + @Ename + '%'";
                SqlCommand cmd = new SqlCommand(myquery, con);
                con.Open();
                cmd.Parameters.Add(new SqlParameter("Ename", txtSearch.Text.Trim()));
                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                int RecordCount = sda.Fill(dt);
                if(RecordCount == 0)
                {
                    string timestamp = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff",CultureInfo.InvariantCulture);
                    DataRow dr = dt.NewRow();
                    dr["Eid"] = 1;//this is because the data type is int
                    dr["Ename"] = "No Records found. " + timestamp.ToString(); ;
                    dt.Rows.Add(dr);
                }
                GridView1.DataSource = dt;
                GridView1.DataBind();
                con.Close();
            }
    
            protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
            {
                GridView1.PageIndex = e.NewPageIndex;
                GridView1.DataBind();
            }
    
            protected void Search_Click(object sender, EventArgs e)
            {
                BindData();
            }

    result:

    Best Regards,

    Jenifer

    Monday, July 22, 2019 3:26 AM
  • User799222684 posted

    In the example, I sent when page first loads, it prints gridview "No records found  2019-07-19 10:07:14.366 ".

    The First Gridview that prints from the !PostBack is ALWAYS at the bottom of the page.

    If the Gridview has records or does NOT have records, when page First loads, that gridview always stays VISIBLE.

    The original Gridview, that first appears  is never updated. I am trying to keep it simple and show the "No records message"

    When I push a button and update the query, that is when I get a SECOND gridview that appears on screen.

    The Second Gridview appears  ABOVE the Original Gridview( as in my example time of "14.366")

    However the gridview data for any updates  does NOT appear in source code. Only the Original Gridview

    appears in the source code.

    I hope this helps.

     

    Monday, July 22, 2019 12:48 PM
  • User799222684 posted

    SOLVED- I found the critter.

    A closing Div before my Gridview 

    </div>     <-  Had no matching Div tag .   I removed that Div and it works OK!!!

    <asp:GridView ID="GridView1" runat="server"

    Monday, July 22, 2019 5:34 PM