更新面板中的Gridview数据未刷新。 [英] Gridview data is not refreshing in the updatepanel.

查看:112
本文介绍了更新面板中的Gridview数据未刷新。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i我正在使用模型弹出扩展器控件。当我点击按钮时,请说明详细信息。数据来自数据库,并在modelpopup中显示gridview ..suppose if我编辑任何值,然后单击关闭按钮。我点击详细信息按钮gridview不刷新。它仅在编辑模式数据中显示。我的代码请帮助我如何重新开始这个..





Hi Everyone,

i am using model popup extender control.when am clicking button let say details.Data coming from database and displaying gridview in modelpopup..suppose if i edit any value and click close button.again i am clicking on details button gridview is not refreshing.it is showing in edit mode data only.here is my code please help me how to reslove this..


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="scriptmnager1" runat="server">

    </asp:ScriptManager>

        <%--<asp:Button id="Button2" runat="server" Text="Click" OnClick="Button2_Click" />--%>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
                     <ContentTemplate>
      <asp:Button id="Button1" runat="server" Text="Button" OnClick="Button1_Click"/>
                         </ContentTemplate>
            </asp:UpdatePanel>

        <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server"

            CancelControlID="btnCancel" OkControlID="btnOkay"

            TargetControlID="Button1" PopupControlID="Panel1"

            PopupDragHandleControlID="PopupHeader" Drag="true"

            BackgroundCssClass="ModalPopupBG">
        </cc1:ModalPopupExtender>

        <asp:Panel id="Panel1" style="display: none" runat="server">
    <table>
        <tr>
            <td>

                <label>products details</label>
            </td>

        </tr>
        <tr>
            <td>
                 <asp:UpdatePanel ID="UpdatePanel2" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
                     <ContentTemplate>
                         <asp:GridView ID="grid1" runat="server" AutoGenerateColumns="false" OnRowUpdating="grid1_RowUpdating" OnRowEditing="grid1_RowEditing">
                             <Columns>
                                 <asp:TemplateField HeaderText="ProductName">
                                     <ItemTemplate>
                                         <asp:Label ID="lblname" runat="server" Text='<%#Eval("productname") %>'></asp:Label>
                                     </ItemTemplate>
                                     <EditItemTemplate>
                                         <asp:TextBox ID="txtname" runat="server"  Text='<%#Eval("productname") %>'></asp:TextBox>
                                     </EditItemTemplate>
                                 </asp:TemplateField>
                                    <asp:TemplateField HeaderText="ProductName">
                                     <ItemTemplate>
                                         <asp:Label ID="lblpcode" runat="server" Text='<%#Eval("productcode") %>'></asp:Label>
                                     </ItemTemplate>
                                     <EditItemTemplate>
                                         <asp:TextBox ID="txtPcode" runat="server"  Text='<%#Eval("productcode") %>'></asp:TextBox>
                                     </EditItemTemplate>
                                 </asp:TemplateField>
                                    <asp:TemplateField>
                                     <ItemTemplate>
                                         <asp:Button ID="btnedit" runat="server" Text="EDIT" CommandName="Edit" />
                                     </ItemTemplate>
                                     <EditItemTemplate>
                                          <asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" />
                                     </EditItemTemplate>
                                 </asp:TemplateField>

                             </Columns>

                         </asp:GridView>

                     </ContentTemplate>
                 </asp:UpdatePanel>

            </td>

        </tr>

    </table>

        </asp:Panel>

    </div>
    </form>
</body>
</html>













protected void Button1_Click(object sender, EventArgs e)
   {
       BindGrid();
       ModalPopupExtender1.Show();
       UpdatePanel1.Update();

   }

   private void BindGrid()
   {
       grid1.Datasource = obj.GetProductsDetails();
       grid1.DataBind();
       UpdatePanel2.Update();
   }










protected void grid1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        grid1.EditIndex = e.NewEditIndex;
        BindGrid();
    }

推荐答案

在UpdatePanel标签中添加此代码。

Add this code within the UpdatePanel tags.
<triggers>
    <asp:asyncpostbacktrigger controlid="Button1" eventname="Click" xmlns:asp="#unknown" />
</triggers>


这篇关于更新面板中的Gridview数据未刷新。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆