我正在使用GridView,我在编辑链接上遇到了两次单击以查看编辑字段问题.以下建议我再次在.RowEditing处理程序上绑定我的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&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
解决方法
找到了.需要设置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