如何在Gridview中使用更新面板 [英] How Do I Use Update Panel in Gridview

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

问题描述

这是我的代码。我在Gridview中有三个按钮,它是addnewRow,DeleteLastRow和Delete Row,当我点击按钮时,Page is Getting Post回到页面顶部。看起来很糟糕。我解决这个问题

 <   asp:UpdatePanel     ID   =  UpdatePanel1    runat   = 服务器    UpdateMode   = 条件   >  
< ContentTemplate >

< asp: GridView ID = GridView1 runat = server AutoGenerateColumns = False

onrowcommand = GridView1_RowCommand ShowFooter = True >
< >
< asp:TemplateField HeaderText < span class =code-keyword> =
用户代码 >
< ItemTemplate >
< asp:TextBox ID = txtusercode runat = server AutoPostBack = true

< span class =code-attribute> ontextchanged = txtusercode_TextChanged > < / asp:TextBox >
< / ItemTemplate >
< / asp:TemplateField < span class =code-keyword>>
< asp:TemplateField HeaderText = 付费日期 >
< ItemTemplate >
< asp:TextBox ID = txtpaiddate runat = server AutoPostBack = true

< span class =code-attribute> o ntextchanged = txtpaiddate_TextChanged > < / asp:TextBox >
< / ItemTemplate > ;
< FooterTemplate >
< asp:按钮 ID = Button1 runat = < span class =code-keyword> s erver onclick = Button1_Click 文本 = 添加新行 / >
< / FooterTemplate >
< / asp:TemplateField >
< span class =code-keyword>< asp:TemplateField HeaderText = TOTAL AMOUNT >
< ItemTemplate >
< asp:TextBox ID = txttotamt runat = server > < < span class =code-leadattribute> / asp:TextBox >
< / ItemTemplate >
< FooterTemplate >
< asp:按钮 ID = btndeleterow runat = server onclick = btndeleterow_Click 文本 = 删除最后一行 / >
< / FooterTemplate >
< / asp:TemplateField >
< asp:TemplateField HeaderText = 删除行 >
< ItemTemplate >
< asp:按钮 ID = BtndelCurrent runat = server CommandArgument = <%#((GridViewRow)容器).RowIndex%> < span class =code-attribute> CommandName = DeleteRow onclick = BtndelCurrent_Click 文字 = 删除行 / >
< / ItemTemplate > ;
< / asp:TemplateField >
< /列 >
< / asp:GridView < span class =code-keyword>>
< / ContentTe mplate >
< / asp:UpdatePanel >







编辑:



还有一件事是Gridview将绑定每个按钮单击事件。

解决方案

你需要在这样的更新面板之前给脚本管理器,



 <   asp:  script   manager     id   =  ScriptManager1    runat   =  server >  
< / asp: script manager >

< asp:updatepanel id = up1 < span class =code-attribute> runat = server >
< contenttemplate >
<! - 此处的代码 - >
< / contenttemplate >
< / asp:updatepanel >


This is my code.I have three button in Gridview ,which is "addnewRow" ,"DeleteLastRow" and "Delete Row" when i click button the Page is Getting Post back to top of the page.its look terrible.how do i solve this

 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" >
    <ContentTemplate>
 
                  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  

                      onrowcommand="GridView1_RowCommand" ShowFooter="True">
                      <Columns> 
                          <asp:TemplateField HeaderText="USER CODE">
                              <ItemTemplate>
                                  <asp:TextBox ID="txtusercode" runat="server" AutoPostBack="true" 

                                      ontextchanged="txtusercode_TextChanged"></asp:TextBox>
                              </ItemTemplate>
                          </asp:TemplateField> 
                          <asp:TemplateField HeaderText="PAID DATE">
                              <ItemTemplate>
                                  <asp:TextBox ID="txtpaiddate" runat="server" AutoPostBack="true" 

                                      ontextchanged="txtpaiddate_TextChanged"></asp:TextBox>
                              </ItemTemplate>
                              <FooterTemplate>
 <asp:Button ID="Button1" runat="server" onclick="Button1_Click"  Text="Add New Row" />
                              </FooterTemplate>
                          </asp:TemplateField>
                          <asp:TemplateField HeaderText="TOTAL AMOUNT">
                              <ItemTemplate>
                                  <asp:TextBox ID="txttotamt" runat="server"></asp:TextBox>
                              </ItemTemplate>
                              <FooterTemplate>
<asp:Button ID="btndeleterow" runat="server" onclick="btndeleterow_Click" Text="Delete Last Row" />  
                              </FooterTemplate>
                          </asp:TemplateField>
                          <asp:TemplateField HeaderText="DELETE  ROW">
                              <ItemTemplate>
   <asp:Button ID="BtndelCurrent" runat="server"  CommandArgument="<%#((GridViewRow)Container).RowIndex %>"  CommandName="DeleteRow" onclick="BtndelCurrent_Click" Text="Delete Row" />
                              </ItemTemplate>
                          </asp:TemplateField>
                      </Columns>
                  </asp:GridView>
                     </ContentTemplate>
    </asp:UpdatePanel>




Edited:

and one more thing is Gridview will bind For each and Every Button Click Event.

解决方案

You need to give Script manager before the update panel like this,

 <asp:scriptmanager id="ScriptManager1" runat="server">
 </asp:scriptmanager>

<asp:updatepanel id="up1" runat="server">
  <contenttemplate>
    <!-- Your code here -->
  </contenttemplate>
</asp:updatepanel>


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

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