弹出窗口关闭后网格无法绑定

时间:2015-06-03 12:53:40

标签: asp.net entity-framework gridview data-binding postback

我有一个gridview,它有一个编辑按钮列。那个按钮打开一个弹出窗口(实际上不是puoup,我使用更新面板,我在下面显示的方式)。那个弹出窗口有一些文本字段来编辑gridview,当我点击保存并关闭时,它会关闭面板,更改db中的gird行,但之后grid不绑定。所以我必须刷新页面。单击保存按钮后我需要刷新。

这是我的弹出行为更新面板:

<form id="form1" runat="server">
    <asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="up" runat="server">
        <ContentTemplate>
            <asp:Panel ID="pnlHider" runat="server" CssClass="hider" Visible="false">
            </asp:Panel>
            <div>
                   //my grid and other controls are here
            </div>
            <asp:Panel ID="pnlModalPopup" runat="server" Visible="false" CssClass="popupbox" >
                Reps:  <asp:TextBox ID="txtReps" runat="server" CssClass="textboxPopup"></asp:TextBox>&nbsp&nbsp
                Weight:  <asp:TextBox ID="txtWeight" runat="server" CssClass="textboxPopup"></asp:TextBox><br /><br />
                <asp:Button ID="btnSave" runat="server" Text="Edit" CssClass="buttonSmall" OnClick="btnSave_Click" />
                <asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="buttonSmall" OnClick="btnCancel_Click"  />
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>
</form>

这是我的保存按钮点击事件:

protected void btnSave_Click(object sender, EventArgs e)
    {

        using(var db= new DWSEntities())
        {
            var set = db.Sets.FirstOrDefault(s => s.ID == setID);
            set.RepCount = Convert.ToInt32(txtReps.Text);
            set.Weight = Convert.ToInt32(txtWeight.Text);
            db.SaveChanges();
            pnlModalPopup.Visible = pnlHider.Visible = false;
            grr = (ListViewDataItem)gv.NamingContainer;
            gvparent = (ListView)grr.NamingContainer;
            keys = gvparent.DataKeys;
            dkey = keys[grr.DataItemIndex];
            int exproId = Convert.ToInt32(dkey.Value);
            var sets = db.Sets.Where(s => s.ExerciseProgramID == exproId).Select(s => new { s.Weight, s.RepCount, s.ID }).ToList();
            gvw.DataSource = sets;
            gvw.DataBind();
        }
    }

0 个答案:

没有答案