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

我正在使用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&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

解决方法

找到了.需要设置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

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....