Modal Popup Extender中的Gridview-回发问题?

时间:2013-02-13 15:01:27

标签: c# asp.net html ajax

我在Ajax Modal Popup(VS2008)中有一个带有gridview的C#.Net应用程序。我将网格视图设置为每页返回10条记录并启用分页。

当用户点击更改gridview中的页面时,会有一个回发关闭模态窗口,然后使用ModalPopup.show()再次打开它;

有没有办法避免整个页面的回发,只是在保持模态窗口活动的同时回发gridview?目前,整个页面的回发给人一种闪烁的印象......

<asp:Panel ID="Panel1" runat="server" Font-Italic="True" 
     Font-Names="Times New Roman" Font-Size="Small" ForeColor="#82B8DE">        


    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
        CellPadding="4" ForeColor="#333333" GridLines="None" 
        onpageindexchanging="GridView1_PageIndexChanging" 
        onrowdatabound="GridView1_RowDataBound" 
        onselectedindexchanged="GridView1_SelectedIndexChanged" 
        SelectedIndex="0" ShowHeader="False" Width="700px" ControlID="GridView1" 
        EventName="PageIndexChanging" Font-Italic="True" Font-Names="Times New Roman" 
        Font-Size="Medium">
         <PagerSettings PageButtonCount="12" />
         <RowStyle CssClass="RowStyle" BackColor="#EFF3FB" Font-Italic="True" 
             Font-Names="Times New Roman" Font-Size="Small" ForeColor="#82B8DE" /> 
        <Columns>
            <asp:BoundField DataField="Address" ReadOnly="True">
            <ItemStyle Width="385px" />
            </asp:BoundField>
            <asp:BoundField DataField="XCoord" ReadOnly="True" ShowHeader="False" >
            <ItemStyle CssClass="Hidden" />
            </asp:BoundField>
            <asp:BoundField DataField="YCoord" ReadOnly="True" ShowHeader="False" >
            <ItemStyle CssClass="Hidden" />
            </asp:BoundField>
        </Columns>
        <FooterStyle CssClass="FooterStyle" BackColor="#507CD1" Font-Bold="True" 
            ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle CssClass="SelectedRowStyle" BackColor="#D1DDF1" 
            Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle CssClass="HeaderStyle" BackColor="#507CD1" Font-Bold="True" 
            ForeColor="White" />

        <EditRowStyle BackColor="#2461BF" Font-Italic="True" 
             Font-Names="Times New Roman" Font-Size="Medium" />
        <AlternatingRowStyle BackColor="White" />

    </asp:GridView>


</asp:Panel>


<ajax:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="Panel1" TargetControlID="dummy" 
BackgroundCssClass="ModalBackgroundGrid" BehaviorID="ModalGrid">
</ajax:ModalPopupExtender>

背后的代码......

public void Page_Load(object sender, EventArgs e)
{

    try
    {
        if (!(Page.IsPostBack))
        {
            GridView1.EnableViewState = true;
            GridView1.AllowPaging = true;
            GridView1.PageSize = 10;
            GridView1.PagerSettings.Mode = PagerButtons.Numeric;
            GridView1.Visible = true;             

        }

        if (!m_bDisclaimerShown)
        {
            m_bDisclaimerShown = true;
            mpe1.Show();
            TabContainer.Visible = true;
            ScaleBar1.Visible = true;


        }
    }
    catch (Exception ex)
    {
        ShowMsg("Error - " + ex.Message);
    }

}

protected void btnHide_Click(object sender, EventArgs e)
{
    mpe1.Hide();
    TabContainer.Visible = true;
    ScaleBar1.Visible = true;

}

protected void cmdZoomAddress_Click(object sender, EventArgs e)
{
    try
    {

        if (txtPostCode.Text.Length >= 7 && OpenDB())
        {
            string strPostcode = txtPostCode.Text;
            strPostcode = strPostcode.Substring(0, 4) + strPostcode.Substring(strPostcode.Length - 3, 3);

            SqlCommand sqlCmd = new SqlCommand();
            sqlCmd.Connection = m_sqlConn;
            sqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
            sqlCmd.CommandText = "sde.dbo.sp_selAddressByPostcode";
            sqlCmd.Parameters.Add("@Postcode", SqlDbType.VarChar);
            sqlCmd.Parameters["@Postcode"].Value = strPostcode;

            SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCmd);
            m_sqlDataTable = new DataTable();
            sqlAdapter.Fill(m_sqlDataTable);

            GridView1.DataSource = m_sqlDataTable;
            GridView1.DataBind();
            GridView1.Visible = true;

            ModalPopupExtender1.Show();

        }

        else
        {
            ShowMsg("Error - No Postal Addresses Returned");
        }
    }
    catch (Exception ex)
    {
        ShowMsg("Error - " + ex.Message);
    }
    finally
    {
        CloseDB();
    }

}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    if (sender != null)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource = m_sqlDataTable;
        GridView1.DataBind();
        ModalPopupExtender1.Show();

    }
}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    GridViewRow GVRow = GridView1.SelectedRow;
    int iX = (int)Convert.ToSingle(GVRow.Cells[1].Text);
    int iY = (int)Convert.ToSingle(GVRow.Cells[2].Text);
    GridView1.Visible = false;

    MoveMap(iX, iY);
}

public void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.DataItemIndex >= 0)
    {
        e.Row.Attributes["style"] = "cursor:pointer";
        e.Row.Attributes.Add("onMouseOver", "this.style.cursor='hand';");
        e.Row.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(GridView1, "Select$" + e.Row.RowIndex.ToString()));
    }

}

protected override void Render(HtmlTextWriter writer)
{

    foreach (GridViewRow r in GridView1.Rows)
    {
        if (r.RowType == DataControlRowType.DataRow)
        {
            Page.ClientScript.RegisterForEventValidation(GridView1.UniqueID, "Select$" + r.RowIndex);
        }
    }

    base.Render(writer);
}

1 个答案:

答案 0 :(得分:0)

感谢您的建议。我把gridview放到了......

<asp:UpdatePanel>
<ContentTemplate>

当我点击网格视图中的记录时,模态现在仍然停留!