All GridView rows disappear while selecting a row

Please consider the values in comments which I got in debug mode:

protected void FilesGrid_SelectedIndexChanged(object sender, EventArgs e)
{
    int selected = FilesGrid.SelectedIndex; // selected = 2
    FilesGrid.DataBind();  //added after feedback in comments. it makes no change
    int count = FilesGrid.Rows.Count; // count = 0
    GridViewRow row = FilesGrid.Rows[selected]; // row = null
    GridViewRow row0 = FilesGrid.Rows[0]; // row = null
}

I came to this code while investigating why SelectedValue gives null in this event handler (the DataKeyNames parameter was set for sure).

Can anybody explain how it is possible?

Thank you in advance.

PS. Here is my aspx code:

<asp:GridView ID="FilesGrid" runat="server" AutoGenerateColumns="False" 
    AutoGenerateSelectButton="True"  
    onselectedindexchanged="FilesGrid_SelectedIndexChanged" 
    style="margin-top: 0px" >
    <Columns>
        <asp:CommandField ShowDeleteButton="True" />
        <asp:BoundField DataField="Name" HeaderText="Name" />
        <asp:BoundField DataField="Length" DataFormatString="{0:N0}" 
            HeaderText="Size in Bytes" HtmlEncode="False" />
    </Columns>
</asp:GridView>

Here is how I bind data:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        string [] dd = {"FullName"};
        FilesGrid.DataKeyNames = dd;

        string appPath = Request.PhysicalApplicationPath; 
        DirectoryInfo dirInfo = new DirectoryInfo(appPath); 
        FileInfo[] files = dirInfo.GetFiles();
        FilesGrid.DataSource = files;
        FilesGrid.DataBind();            } 
}

Y copy pasted your code, delete this line FilesGrid.DataBind() in the FilesGrid_SelectedIndexChanged, i see that are 2 methods that you are not posting, that aren't in the code that you posted the onselectedindexchanging, onrowdeleting events, comment them from the aspx and see if it works, or se if that events are not doing something tricking, that are deleting the rows in your GridView.

Tell me if it works

I did this

  protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string[] dd = { "FullName" };
            FilesGrid.DataKeyNames = dd;

            string appPath = Request.PhysicalApplicationPath;
            DirectoryInfo dirInfo = new DirectoryInfo(appPath);
            FileInfo[] files = dirInfo.GetFiles();
            FilesGrid.DataSource = files;
            FilesGrid.DataBind();
        }
    }
    protected void FilesGrid_SelectedIndexChanged(object sender, EventArgs e)
    {
        int selected = FilesGrid.SelectedIndex; // selected = 2
        //FilesGrid.DataBind();  //added after feedback in comments. it makes no change
        int count = FilesGrid.Rows.Count; // count = 0
        GridViewRow row = FilesGrid.Rows[selected]; // row = null
        GridViewRow row0 = FilesGrid.Rows[0]; // row = null
    }
    protected void FilesGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

    }
    protected void FilesGrid_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {

    }

The aspx code.

<asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true"
            AsyncPostBackTimeout="0" EnableScriptLocalization="true">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="upPanel" runat="server">
            <ContentTemplate>        
                <asp:GridView ID="FilesGrid" runat="server" AutoGenerateColumns="False" AutoGenerateSelectButton="True"
                    OnRowDeleting="FilesGrid_RowDeleting" OnSelectedIndexChanged="FilesGrid_SelectedIndexChanged"
                    Style="margin-top: 0px" OnSelectedIndexChanging="FilesGrid_SelectedIndexChanging">
                    <Columns>
                        <asp:CommandField ShowDeleteButton="True" />
                        <asp:BoundField DataField="Name" HeaderText="Name" />
                        <asp:BoundField DataField="Length" DataFormatString="{0:N0}" HeaderText="Size in Bytes"
                            HtmlEncode="False" />
                    </Columns>
                </asp:GridView>
            </ContentTemplate>         
        </asp:UpdatePanel>

GridView data disappears in when selecting row using ListDetails , When I click Select for a given row, however, all text (but not foreign-key) fields in that row are blanked out. Is this a bug or is it by design? Gridview Select Row Without Using SELECT Button. You can Highlight a Row in GridView by using the onmouseover event. The following code will color the GridView row while mouse overing. How to get selected row values from a Gridview control. You can catch the GridView Cell value at the OnSelectedIndexChanged event.


remove the FilesGrid.DataBind(); //added after feedback in comments. it makes no change When I add that statement to my code I am getting the error. after removing that please try again. If not working please share the

protected void FilesGrid_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) method code, may be something wrong with that section

T563130 - ASPxGridView, I have a gridview that has many rows - based on the data. I want to do the following. When I select a row, all the other rows will disappear  GridView with CheckBox – Select All or Check All and Highlight Selected Row, CheckBox in GridView to select row and to select all row.. We can include checkbox in every row of GridView to enable selection of that particular row. To do this, we need to include a TemplateColumn that has a CheckBox control inside it.


The issue was resolved by commenting out the line // if (!Page.IsPostBack). It looks like the data source is lost somehow during the postback. The whole seems to be a local bug with ViewState, because this behavior was not observed by other users. My special thanks to Tim Schmelter and naveen.

Gridview disappear while edit and click update button in the , The best thing you would do for this situation is to debug your code. Set a break-​point to your BindGridView() method after hitting the  Can you add another column called numbers so all the rows appear a number: <asp:TemplateField> <ItemTemplate> <%# Container.DataItemIndex + 1 %> </ItemTemplate> </asp:TemplateField> The code is from this link: How to display row numbers in GridView. Then click on the button to see whether it delete the row that has numbers.


You can keep Page.IsPostBack in Page_Load, I was having the same issue and it turns out the grid was not in ViewState in my case. If you use Linq query in your controller you will want to add this property to the grid so it will keep refreshing properly: <asp:Panel EnableViewState="True">

RESOLVED** Gridview disappears after clicking Edit button, On my web form, when users select an employee name from However, when I click the edit button in Gridview2, the gridview disappears 'close/dispose all objects here that the selected index is -1, regardless of which row I select. On postback, if gridview #1 has no data due to it fetching no rows as  After clicking on the Select All button, you can right-click on one of the row numbers and select "Unhide" You can also select row 387 and drag your mouse up slowly until you see a pop-up that tells you that you have selected 387 Rows (see the "21R" pop-up in the image below). Then right-click on row 387 and select "Unhide"


GridView.RowEditing Event (System.Web.UI.WebControls , Occurs when a row's Edit button is clicked, but before the GridView control enters edit mode. Rows.Add(tableRow); } //Persist the table in the Session object. In this article I will explain with an example, how to display (show) GridView Selected Row in FormView control in ASP.Net using C# and VB.Net. HTML Markup The HTML Markup consists of an ASP.Net GridView with two BoundField columns, one hidden TemplateField column with a Label and one ButtonField column which consists of a Select Button to


Set Filter: Enterprise Grade Feature of our Datagrid, This is because when sorting rows, row data exists. The expected flow when using the search box would be uncheck "Select All", type what could give the impression that the filter is broken because it is missing Wednesday as an option. I have a select query which is based on two criterias. if the order is in process or if the order is received. The datagridview will show all the records from the database,,,, I want to disable the rows in datagridview which will be in received statusonly the on order should be editable


Cell content disappearing when scrolling horizontally in UI for , Grid has first few columns which are static (predefined) the rest of the Since all other grids are working fine, I'm assuming it has something to do with Select is picked based on current object in that cell, current user that is At the moment we have implemented paging to limit amount of rows displayed.