locked
Phantom gridview created upon selecting a row in main gridview RRS feed

  • Question

  • User-1682676269 posted

    Hi there,

    I have a main gridvew and when you select a row it updates a secondary gridview below it.

     The columns in this main table are autogenerated,  when I select a row from the main gridview, the secondary gridview will show the correct data but another gridview (a copy of the second) appears below. Subsequent selections alter the 2nd gridview as it should but the phantom gridview is still there.

     I've just pasted the code for my custom page below but i'm just not sure where to start looking for this bug because it happens in the default templates aswell. Maybe it's a master page problem or is it stylesheet?

    If anybody has any ideas that would be great.

    Cheers.

    Mel

    <%@ Page Language="C#" MasterPageFile="~/Site.master" CodeBehind="ListDetails.aspx.cs"
        Inherits="CodeGenDD.ListDetailsBatch" %>

    <%@ Register src="~/DynamicData/Content/GridViewPager.ascx" TagName="GridViewPager"
        TagPrefix="asp" %>
    <%@ Register src="~/DynamicData/Content/FilterUserControl.ascx" TagName="DynamicFilter"
        TagPrefix="asp" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
        <asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true" />
        <p>
            <b>
                <%= GridDataSource.GetTable().GetDescription() %></b></p>
        <br />
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
            HeaderText="List of validation errors" />
        <asp:DynamicValidator runat="server" ID="GridViewValidator" ControlToValidate="GridView1"
            Display="None" />
        <asp:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="GridView2"
            Display="None" />
        <asp:FilterRepeater ID="FilterRepeater" runat="server">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Eval("DisplayName") %>' AssociatedControlID="DynamicFilter$DropDownList1" />
                <asp:DynamicFilter runat="server" ID="DynamicFilter" OnSelectedIndexChanged="OnFilterSelectedIndexChanged" />
            </ItemTemplate>
            <FooterTemplate>
                <br />
                <b></b>
                <br />
            </FooterTemplate>
        </asp:FilterRepeater>
        <div class="rounded panel">
            <!-- Header -->
            <div class="top-outer">
                <div class="top-inner">
                    <div class="top">
                        <div class="header">
                            <h2>
                                <%= GridDataSource.GetTable().DisplayName %></h2>
                        </div>
                    </div>
                </div>
            </div>
            <asp:ScriptManagerProxy runat="server" ID="ScriptManagerProxy1" />
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <!-- GridView -->
                    <div class="mid-outer">
                        <div class="mid-inner">
                            <div class="mid">
                                <div class="body">
                                    <asp:GridView ID="GridView1" runat="server" AutoGenerateSelectButton="True"
                                        AutoGenerateEditButton="True" AutoGenerateDeleteButton="True" AllowPaging="True"
                                        AllowSorting="True" OnDataBound="OnGridViewDataBound" OnRowEditing="OnGridViewRowEditing"
                                        OnSelectedIndexChanging="OnGridViewSelectedIndexChanging" OnRowDeleted="OnGridViewRowDeleted"
                                        OnRowUpdated="OnGridViewRowUpdated" OnRowCreated="OnGridViewRowCreated"
                                        CssClass="grid" ShowFooter="True"
                                        DataSourceID="GridDataSource" DataKeyNames="BatchId">
                                        <PagerStyle CssClass="pager" />
                                        <SelectedRowStyle CssClass="selected" />
                                        <RowStyle CssClass="row" />
                                       
                                        <Columns>
                                           
                                         
                                        </Columns>
                                       
                                        <PagerTemplate>
                                            <asp:GridViewPager runat="server" />
                                           <%-- <asp:Button ID="Button1" runat="server" Text="Button" />--%>
                                        </PagerTemplate>
                                        <EmptyDataTemplate>
                                            There are currently no items in the
                                            <%= GridDataSource.GetTable().DisplayName %>
                                            table.
                                        </EmptyDataTemplate>
                                        <AlternatingRowStyle CssClass="altrow" />
                                    </asp:GridView>
                                </div>
                            </div>
                        </div>
                    </div>
                  
                    <!-- Footer -->
                    <div class="bottom-outer">
                        <div class="bottom-inner">
                            <div class="bottom">
                            </div>
                        </div>
                    </div>
                    </div>
                     <br />
                    <asp:LinqDataSource ID="GridDataSource" runat="server" >
                       
                        <WhereParameters>
                            <asp:Parameter />
                        </WhereParameters>
                    </asp:LinqDataSource>
                  
                    <asp:Panel ID="DetailsPanel" runat="server" Height="589px">
                       
                        <br />
                        <div class="rounded panel">
                            <!-- Header -->
                            <div class="top-outer">
                                <div class="top-inner">
                                    <div class="top">
                                        <div class="header">
                                            <h2>
                                            </h2>
                                        </div>
                                    </div>
                                </div>
                            </div>
                       <!-- DetailsView -->
                            <div class="mid-outer">
                                <div class="mid-inner">
                                    <div class="mid">
                                        <div class="body">
                                          <asp:GridView ID="GridView2" runat="server"
                                        AllowSorting="True" CssClass="grid" ShowFooter="True" AutoGenerateColumns="False"
                                        DataSourceID="GridDataSource2" DataKeyNames="BatchLineId" EnableViewState="False">
                                        <PagerStyle CssClass="pager" />
                                        <SelectedRowStyle CssClass="selected" />
                                        <RowStyle CssClass="row" />
                                       
                                        <Columns>
                                          
                                            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                                          
                                           
                                            <asp:DynamicField DataField="ContainerCodeId" HeaderText="Container Code"
                                                SortExpression="ContainerCodeId" />
                                            <asp:DynamicField DataField="ContainerQuantity" HeaderText="Container Qty"
                                                SortExpression="ContainerQuantity" />
                                            <asp:DynamicField DataField="SupplierReference" HeaderText="Supplier Ref"
                                                SortExpression="SupplierReference" />
                                            <asp:CheckBoxField DataField="IsActive" HeaderText="Is Active"
                                                SortExpression="IsActive" />
                                            <asp:DynamicField DataField="DateReceived" HeaderText="Date Received"
                                                SortExpression="DateReceived" />
                                            <asp:DynamicField DataField="MarketReference" HeaderText="Market Ref"
                                                SortExpression="MarketReference" />
                                            <asp:DynamicField DataField="DateCreated" HeaderText="Date Created"
                                                SortExpression="DateCreated" />
                                            <asp:DynamicField DataField="DateLastUpdated" HeaderText="Updated"
                                                SortExpression="DateLastUpdated" />
                                           
                                        </Columns>
                                       
                                        <PagerTemplate>
                                            <asp:GridViewPager ID="GridViewPager1" runat="server" />
                                        </PagerTemplate>
                                        <EmptyDataTemplate>
                                            There are currently no items in the
                                            <%= GridDataSource2.GetTable().DisplayName %>
                                            table.
                                        </EmptyDataTemplate>
                                        <AlternatingRowStyle CssClass="altrow" />
                                    </asp:GridView>
                                </div>
                            </div>
                        </div>
                    </div>
                  
                    <!-- Footer -->
                    <div class="bottom-outer">
                        <div class="bottom-inner">
                            <div class="bottom">
                            </div>
                        </div>
                    </div>
                    </div>
                     <br />
                    <asp:LinqDataSource ID="GridDataSource2" runat="server" EnableDelete="True"
                        EnableUpdate="True"
                            ContextTypeName="FCCOnlineNetting.data.FCCOnlineNettingDataDataContext"
                            TableName="BatchLines" Where="BatchId == @BatchId"
                        >
                        <WhereParameters>
                                <asp:ControlParameter ControlID="GridView1" DefaultValue="-1" Name="BatchId"
                                    PropertyName="SelectedValue" Type="Int32" />
                            </WhereParameters>
                    </asp:LinqDataSource>
                      
                    </asp:Panel>
                   
                </ContentTemplate>
               
            </asp:UpdatePanel>

    </asp:Content>

    Code behind: (Ignore the DetailsView bits they are not being used)

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Xml.Linq;
    using System.Web.DynamicData;
    using Microsoft.Web.DynamicData;

    namespace CodeGenDD
    {
        public partial class ListDetailsBatch : System.Web.UI.Page
        {
            protected void Page_Init(object sender, EventArgs e)
            {
                DynamicDataManager1.RegisterControl(GridView1, true /*setSelectionFromUrl*/);
                DynamicDataManager1.RegisterControl(GridView2);

                MetaTable table1 = GridDataSource.GetTable();
                MetaTable table2 = GridDataSource2.GetTable();

                GridView1.ColumnsGenerator = new AdvancedFieldGenerator(table1, true);
                GridView2.ColumnsGenerator = new AdvancedFieldGenerator(table2, true);
            }

            protected void Page_Load(object sender, EventArgs e)
            {
                MetaTable table = GridDataSource.GetTable();
                Title = table.DisplayName;

               

                 //Disable various options if the table is readonly
               
                    //DetailsPanel.Visible = false;
                   //GridView1.AutoGenerateSelectButton = false;
                    GridView1.AutoGenerateEditButton = false;
                    GridView1.AutoGenerateDeleteButton = false;


               
            }
            protected void OnGridViewDataBound(object sender, EventArgs e)
            {
                if (GridView1.Rows.Count == 0)
                {
                   // DetailsView1.ChangeMode(DetailsViewMode.Insert);
                }
            }
            protected void OnFilterSelectedIndexChanged(object sender, EventArgs e)
            {
                GridView1.EditIndex = -1;
                GridView1.PageIndex = 0;
                //DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
            }
            protected void OnGridViewRowEditing(object sender, EventArgs e)
            {
                //DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
            }
            protected void OnGridViewSelectedIndexChanging(object sender, EventArgs e)
            {
                GridView1.EditIndex = -1;
                //DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
               
            }

            protected void OnGridViewRowCreated(object sender, GridViewRowEventArgs e)
            {
                SetDeleteConfirmation(e.Row);
            }

            protected void OnGridViewRowDeleted(object sender, GridViewDeletedEventArgs e)
            {
               // DetailsView1.DataBind();
            }

            protected void OnGridViewRowUpdated(object sender, GridViewUpdatedEventArgs e)
            {
                //DetailsView1.DataBind();
            }

            protected void OnDetailsViewItemDeleted(object sender, DetailsViewDeletedEventArgs e)
            {
                GridView1.DataBind();
            }

            protected void OnDetailsViewItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
            {
                GridView1.DataBind();
            }

            protected void OnDetailsViewItemInserted(object sender, DetailsViewInsertedEventArgs e)
            {
                GridView1.DataBind();
            }

            protected void OnDetailsViewModeChanging(object sender, DetailsViewModeEventArgs e)
            {
                if (e.NewMode != DetailsViewMode.ReadOnly)
                {
                    GridView1.EditIndex = -1;
                }
            }

            protected void OnDetailsViewPreRender(object sender, EventArgs e)
            {
                ////int rowCount = DetailsView1.Rows.Count;
                //if (rowCount > 0)
                //{
                //   // SetDeleteConfirmation(DetailsView1.Rows[rowCount - 1]);
                //}
            }

            private void SetDeleteConfirmation(TableRow row)
            {
                foreach (Control c in row.Cells[0].Controls)
                {
                    if (c is LinkButton)
                    {
                        LinkButton btn = (LinkButton)c;
                        if (btn.CommandName == DataControlCommands.DeleteCommandName)
                        {
                            btn.OnClientClick = "return confirm('Are you sure you want to delete this item?');";
                        }
                    }
                }
            }

          
        }
    }
    Thursday, December 4, 2008 9:15 PM

All replies

  • User-797310475 posted

    Could you maybe post some screenshots of what you mean by phantom grid view?

    Friday, December 5, 2008 2:53 PM
  • User-1005219520 posted

    Hey Mel,

    Can you reproduce this with NorthWind or AdventureWorksLT and the default page templates? Then it will be easy for us to investigate.

     

    Friday, December 5, 2008 4:44 PM