微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/aspnet/247871.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐