asp.net – Gridview编辑,点击两次问题

前端之家收集整理的这篇文章主要介绍了asp.net – Gridview编辑,点击两次问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用GridView,我在编辑链接上遇到了两次单击以查看编辑字段问题.以下建议我再次在.RowEditing处理程序上绑定我的GridView.问题仍然存在,我在第二次点击任何编辑链接后才看到编辑字段.
  1. <%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
  2. CodeBehind="Default.aspx.vb" Inherits="GridViewTest._Default" %>
  3.  
  4. <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
  5. </asp:Content>
  6. <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
  7. <h2>
  8. Welcome to ASP.NET!
  9. </h2>
  10. <p>
  11. To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
  12. <asp:GridView ID="gvReport" runat="server" AutoGenerateColumns="False"
  13. AutoGenerateEditButton="True">
  14. <Columns>
  15. <asp:BoundField DataField="c1" HeaderText="C1" />
  16. <asp:BoundField DataField="c2" HeaderText="C2" />
  17. <asp:BoundField DataField="c3" HeaderText="C3" />
  18. <asp:BoundField DataField="c4" HeaderText="C4" />
  19. <asp:BoundField DataField="c5" HeaderText="C5" />
  20. <asp:BoundField DataField="c6" HeaderText="C6" />
  21. <asp:BoundField DataField="c7" HeaderText="C7" />
  22. <asp:BoundField DataField="c8" HeaderText="C8" />
  23. </Columns>
  24. </asp:GridView>
  25. </p>
  26. <p>
  27. You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409"
  28. title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
  29. </p>
  30. </asp:Content>
  31.  
  32.  
  33.  
  34.  
  35.  
  36. Public Class _Default
  37. Inherits System.Web.UI.Page
  38.  
  39. Protected Sub Page_Load(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.Load
  40. If Not IsPostBack Then
  41. loaddata()
  42. End If
  43. End Sub
  44.  
  45. Sub loaddata()
  46.  
  47. 'Get dataview dvAgTarRet_gv
  48.  
  49.  
  50.  
  51. gvReport.DataSource = dvAgTarRet_gv
  52. gvReport.DataBind()
  53. Session.Add("gvReport",dvAgTarRet_gv)
  54.  
  55. end sub

解决方法

找到了.需要设置gridview的EditIndex,然后执行数据绑定.
  1. Private Sub gvReport_RowEditing(sender As Object,e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvReport.RowEditing
  2. gvReport.DataSource = CType(Session("gvReport"),DataView)
  3. gvReport.EditIndex = e.NewEditIndex
  4. gvReport.DataBind()
  5. End Sub

猜你在找的asp.Net相关文章