简体   繁体   English

在更新面板中刷新gridview

[英]Refresh gridview inside update panels

i have a page which is inside update panel.it contains two gridview which are also inside update panels.im binding them in page load inside !ispostback as well as other parts of code.when i bind only first grid it works fine but when i bind the second grid it refreshes the first one and it shows no data.is this the problem of improper usage of update panel usage or any other issue.. how can i use the triggers here. 我有一个页面位于更新面板内部。它包含两个也在更新面板内部的gridview.im将它们绑定到页面加载中的isisbackback以及代码的其他部分中。当我仅绑定第一个网格时,它工作正常,但是当我绑定第二个网格,它将刷新第一个网格,并且不显示任何数据。这是更新面板使用不当或任何其他问题的问题。我如何在这里使用触发器。

my code is as follows.. 我的代码如下。

<asp:UpdatePanel ID="updgrd1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" Width="85%"ShowHeaderWhenEmpty="true"EmptyDataText="No Records Found" AutoGenerateColumns="false"OnRowCancelingEdit="GridView1_RowCancelingEdit"OnRowEditing="G dView1_RowEditing">
<Columns>
//my code here
 </Columns>
 </asp:GridView>

</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnUpdate" EventName="Click" />

</Triggers>
</asp:UpdatePanel>


 <asp:UpdatePanel ID="updgrd2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
 <asp:GridView ID="GridView2" runat="server" Width="85%" ShowHeaderWhenEmpty="true"  AutoGenerateColumns="false" EmptyDataText="No Records Found">
<Columns>
 //my code here
 </Columns>
 </asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnUpdate" EventName="Click" />
 <asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" />
</Triggers>
 </asp:UpdatePanel>

protected void Page_Load(object sender, EventArgs e)
{
if(!ispostback)
{
LoadGrid1();
LoadGrid2();
}
}

Here I'm doing exactly what you are. 在这里,我正在做什么。 Here I have a textbox and a gridview, when clicking add whatever is in the textbox gets added to the gridview. 在这里,我有一个文本框和一个gridview,单击添加时,文本框中的任何内容都会添加到gridview。

 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
     <Triggers>
       <asp:AsyncPostBackTrigger controlid="LnkAddTrack" eventname="Click" />         
     </Triggers>  

       <ContentTemplate>
         <div id="EventTrack" >
            <asp:Label ID="lblEventTracks" runat="server" Text="Event Tracks"></asp:Label>&nbsp;
            <asp:TextBox ID="txtEventTracks" CssClass="EventTextbox" runat="server"></asp:TextBox> 
            <asp:LinkButton ID="LnkAddTrack" ClientIDMode="Static"  runat="server" OnClick="LnkAddTrack_Click">Add Track</asp:LinkButton>
            </div>   

<asp:GridView ID="dgTracks"  runat="server" >
               <Columns> 
                   <asp:TemplateField HeaderText="TrackName">
                        <ItemTemplate>                       
                            <asp:Label ID="Control" runat="server" Text='<%#   Eval("TrackName") %>'></asp:Label>                        
                        </ItemTemplate>                                        

                   </asp:TemplateField>
               </Columns>
            </asp:GridView>
       </ContentTemplate>
  </asp:UpdatePanel>

Then make sure you on your button event to add new data you are adding the data correctly and remember to rebind the gridview. 然后,确保您在按钮事件上添加了新数据,然后正确添加了数据,并记住要重新绑定gridview。

 protected void LnkAddTrack_Click(object sender, EventArgs e)
    {
        InsertTrack();
        DgPopTracks();
    }

Ask any questions you may have, if you want to see my Insert Track and DgPopTracks events i can post them as well for you 提出任何问题,如果您想查看我的插入轨迹和DgPopTr​​acks事件,我也可以为您发布

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM