【问题标题】:is possible Refresh Gridview from another page?是否可以从另一个页面刷新 Gridview?
【发布时间】:2017-12-01 03:10:45
【问题描述】:

我想知道当用户从另一个网页更新或删除项目时是否可以刷新网格视图。 这是我们的网格视图之一:

<asp:GridView ID="gvw_CliEmp_EmpDataNo" runat="server" AutoGenerateColumns="false"
        CssClass="mGrid" PagerStyle-CssClass="pgr" Width="50%"  
        AlternatingRowStyle-CssClass="alt" Font-Size="Small"
        OnRowCommand="gvw_CliEmp_EmpDataNo_RowCommand">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <a href="#" onclick="window.open('Clientes_Empleados_DetalleNO.aspx?cliCod= <%#Eval("ClienteCodigo1").ToString() 
                        + "&EmpNom=" + Eval("Empleado1").ToString()
                        + "&EmpCod=" + Eval("IdCliEmp").ToString()
                        + "&EmpNiv=" + Eval("NivelAcceso1").ToString()    
                        %> ','PrintMe','height=500px,width=800px,scrollbars=1');">Editar</a>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="ID EMP">
                <ItemTemplate>
                    <asp:Label ID="lbl_CliEmp_EmpIdNo" runat="server" Text='<%# Eval("IdCliEmp") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="EMPLEADO">
                <ItemTemplate>
                    <asp:Label ID="lbl_CliEmp_EmpNomNo" runat="server" Text='<%# Eval("Empleado1") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="CLIENTE">
                <ItemTemplate>
                    <asp:Label ID="lbl_CliEmp_CliCodNo" runat="server" Text='<%# Eval("ClienteCodigo1") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="NIVEL">
                <ItemTemplate>
                    <asp:Label ID="lbl_CliEmp_EmpNivNo" runat="server" Text='<%# Eval("NivelAcceso1") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:LinkButton ID="lnkdeleteNo" runat="server" CommandName="DeleteNo" 
                        CommandArgument='<%#Eval("IdCliEmp")%>'>Eliminar
                    </asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

如果用户单击编辑按钮会出现另一个网页,例如弹出窗口但更简单,为此我将值发送到这个新的网络表单:

string empNombre, clienteCodigo, empCodigo, empNivel;


protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        empNombre = Request.QueryString["EmpNom"];
        clienteCodigo = Request.QueryString["cliCod"];
        empCodigo = Request.QueryString["EmpCod"];
        empNivel = Request.QueryString["EmpNiv"];

        lbl_CliEmpDet_CliNomNO.Text = empNombre;
        lbl_CliEmpDet_CliCodNO.Text = clienteCodigo.Replace(" ", "");
        lbl_CliEmpDet_EmpCodNO.Text = empCodigo.Replace(" ", "");
        lbl_CliEmpDet_CliNivNO.Text = empNivel.Replace(" ", "");

        clietnes_Empleados_Cons_DptosxCliente(); //departamentos por cliente

    }
}

还有 bla bla blah...我从第一页获取数据, 但是,当我从第二页更新或删除记录时,我希望第一页上的 gridview 更新而不刷新。

这可能吗? 我希望任何人都可以帮助我。

PD:我没有使用 ajax。

最好的问候

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

    是的,这是可能的!每当用户更新或删除时,您都可以创建一个 会话会话值填充了一些“文本”,并且在页面加载事件的 Grid View Web 表单上,您可以检查会话值是否是“文本”,然后刷新网格视图。

    如果我的回答对你有帮助,标记为正确。

    【讨论】:

      【解决方案2】:

      在您的 GridView 页面上,使用 onclick 事件创建一个隐藏按钮,该事件只会重新绑定 GridView。

      <div style="display: none;">
          <asp:Button runat="server" ID="btnRefreshGrid" OnClick="btnRefreshGrid_Click"></button>
      </div>
      
      protected void btnRefreshGrid_Click(object sender, EventArgs e)
      {
          gridView.Rebind();
      }
      

      在单击按钮的同一页面上创建一个 JavaScript 事件。

      function refreshGrid(){
          document.getElementById("<%= btnRefreshGrid.ClientID %>").click();
      }
      

      然后,在您的弹出窗口中,只需使用 parent 关键字在 JavaScriot 中调用此函数。

      //database changes made
      parent.refreshGrid();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-09
        相关资源
        最近更新 更多