Results 1 to 3 of 3

Thread: gridview is disappearing

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    gridview is disappearing

    Here is my aspx page:
    Code:
    <&#37;@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="GridViewDisappearing._Default" %>
    
    <%@ Register Assembly="GridViewDisappearing" Namespace="GridViewDisappearing" TagPrefix="cc1" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
                DataSourceID="SqlDataSource1">
                <Columns>
                    <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" />
                    <asp:BoundField DataField="Product" HeaderText="Product" SortExpression="Product" />
                    <asp:BoundField DataField="Warehouse" HeaderText="Warehouse" SortExpression="Warehouse" />
                    <asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" />
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SampleDBConnectionString %>"
                SelectCommand="SELECT [ID], [Product], [Warehouse], [Quantity] FROM [Inventory]">
            </asp:SqlDataSource>
            <asp:Button ID="Button1" runat="server" Text="Button" />
        </div>
        </form>
    </body>
    </html>
    And here is the code behind:
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace GridViewDisappearing
    {
        public partial class _Default : MyPage1
        {
            protected void Page_Init(object sender, EventArgs e)
            {
                int x =  GridView1.Rows.Count;
            }
    
            protected void Page_Load(object sender, EventArgs e)
            {
                
            }
    
           
        }
    }
    The first time the page is requested, it displays the gridview with the data. But when I click on the button, the gridview disappears (and only the button shows up). When I comment out the code:
    int x = GridView1.Rows.Count;

    in the Page_Init(), the gridview does NOT disappear. Why is that one line of code causing it to disappear?
    Last edited by benmartin101; Aug 15th, 2011 at 12:58 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width