2011-03-25 101 views
7

我正在使用一个GridView,并且我在编辑链接中遇到了两次点击来查看编辑字段问题。在建议之后,我再次在.RowEditing处理程序上绑定我的GridView。问题依然存在,我只在第二次点击任何编辑链接后才看到编辑字段。Gridview编辑,点击两次问题

<%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false" 
    CodeBehind="Default.aspx.vb" Inherits="GridViewTest._Default" %> 

    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> 
    </asp:Content> 
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> 
     <h2> 
      Welcome to ASP.NET! 
     </h2> 
     <p> 
      To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>. 
      <asp:GridView ID="gvReport" runat="server" AutoGenerateColumns="False" 
       AutoGenerateEditButton="True"> 
       <Columns> 
        <asp:BoundField DataField="c1" HeaderText="C1" /> 
        <asp:BoundField DataField="c2" HeaderText="C2" /> 
        <asp:BoundField DataField="c3" HeaderText="C3" /> 
        <asp:BoundField DataField="c4" HeaderText="C4" /> 
        <asp:BoundField DataField="c5" HeaderText="C5" /> 
        <asp:BoundField DataField="c6" HeaderText="C6" /> 
        <asp:BoundField DataField="c7" HeaderText="C7" /> 
        <asp:BoundField DataField="c8" HeaderText="C8" /> 
       </Columns> 
      </asp:GridView> 
     </p> 
     <p> 
      You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409" 
       title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>. 
     </p> 
    </asp:Content> 





    Public Class _Default 
     Inherits System.Web.UI.Page 

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
      If Not IsPostBack Then 
       loaddata() 
      End If 
     End Sub 

     Sub loaddata() 

     'Get dataview dvAgTarRet_gv 



      gvReport.DataSource = dvAgTarRet_gv 
        gvReport.DataBind() 
      Session.Add("gvReport", dvAgTarRet_gv) 

      end sub 
+1

您需要背后张贴你的代码来说明你是如何数据绑定。这听起来像是你不恰当地将数据绑定到了gridview并且失去了viewstate,因此这个事件不能和原来的控制状态相关联。如果页面不处于使用Page.Postback的回发模式,则尝试仅绑定。 – 2011-03-25 14:30:38

+0

Brian,好吧,我现在有一个空的.RowEditing处理程序。并在点击编辑后,导致回发我没有看到任何文本框/页面更改? – fran 2011-03-25 14:49:07

+0

fran,您需要发布您的代码/标记进行审查。 – 2011-03-25 15:38:45

回答

17

找到它。需要设置gridview的EditIndex,然后做一个数据绑定。

Private Sub gvReport_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvReport.RowEditing 
    gvReport.DataSource = CType(Session("gvReport"), DataView) 
    gvReport.EditIndex = e.NewEditIndex 
    gvReport.DataBind() 
End Sub 
+0

在我读过的这个问题的100个“解决方案”中,这是一个有效的方法。谢谢你。 – AnotherDeveloper 2014-01-09 21:05:16

+1

+1肯定会根据每个代码添加特定的数据绑定方法。 – bonCodigo 2014-07-07 10:04:32

3

只需拨打您的网格绑定功能:

protected void GvEmployee_RowEditing(object sender, GridViewEditEventArgs e) 
{ 
    GvEmployee.EditIndex = e.NewEditIndex; 
    bindgridview(); // method of binding gridview 
}