2011-03-25 62 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 
} 
相關問題