0

我在 Ajax 模态弹出窗口 (VS2008) 中有一个带有 gridview 的 C# .Net 应用程序。我将网格视图设置为在启用分页的情况下每页返回 10 条记录。

当用户单击以更改网格视图中的页面时,会有一个回发关闭模式窗口,然后使用 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);
}
4

1 回答 1

0

谢谢你的建议。我已将gridview放入...

<asp:UpdatePanel>
<ContentTemplate>

模态现在仍然存在,但是当我单击网格视图中的记录时,它不会关闭!

于 2013-02-13T15:15:19.143 回答