本文介绍了gridview的编辑,点击两次问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是GridView和我遇到两次单击编辑链接,查看编辑字段问题。以下建议我对.RowEditing处理程序再次结合我的GridView。问题仍然存在,我只看到我的任何修改链接的第二次点击后,编辑字段。

 <%@页标题=主页LANGUAGE =VB的MasterPageFile =〜/的Site.MasterAutoEventWireup =假
    codeBehind =Default.aspx.vb继承=GridViewTest._Default%GT;    < ASP:内容ID =HeaderContent=服务器ContentPlaceHolderID =HeadContent>
    < / ASP:内容>
    < ASP:内容ID =的BodyContent=服务器ContentPlaceHolderID =日程地址搜索Maincontent>
        < H2>
            欢迎到ASP.NET!
        < / H>
        &所述p为H.;
            要了解更多关于ASP.NET访问< A HREF =htt​​p://www.asp.net称号=ASP.NET网站> www.asp.net< / a取代。
            < ASP:GridView控件ID =gvReport=服务器的AutoGenerateColumns =FALSE
                AutoGenerateEditButton属性=真>
                <柱体和GT;
                    < ASP:BoundField的数据字段=C1的HeaderText =C1/>
                    < ASP:BoundField的数据字段=C2的HeaderText =C2/>
                    < ASP:BoundField的数据字段=C3的HeaderText =C3/>
                    < ASP:BoundField的数据字段=C4的HeaderText =C4/>
                    < ASP:BoundField的数据字段=C5的HeaderText =C5/>
                    < ASP:BoundField的数据字段=6的HeaderText =C6/>
                    < ASP:BoundField的数据字段=C7的HeaderText =C7/>
                    < ASP:BoundField的数据字段=8的HeaderText =8/>
                < /专栏>
            < / ASP:GridView的>
        &所述; / P>
        &所述p为H.;
            您还可以找到< A HREF =htt​​p://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409
                标题=MSDN文档ASP.NET>对于MSDN和LT上的ASP.NET文件; / a取代。
        &所述; / P>
    < / ASP:内容>    公共类_Default
        继承System.Web.UI.Page        保护小组的Page_Load(BYVAL发件人为对象,BYVAL E上System.EventArgs)把手Me.Load
            如果没有的IsPostBack然后
                loaddata()
            万一
        结束小组        子loaddata()        '获取数据视图dvAgTarRet_gv            gvReport.DataSource = dvAgTarRet_gv
                    gvReport.DataBind()
            Session.Add(gvReport,dvAgTarRet_gv)            分结束


解决方案

发现了它。需要设置GridView的EditIndex,然后做一个数据绑定。

 私人小组gvReport_RowEditing(发送者为对象,E作为System.Web.UI.WebControls.GridViewEditEventArgs)处理gvReport.RowEditing
    gvReport.DataSource = CTYPE(会议(gvReport),数据视图)
    gvReport.EditIndex = e.NewEditIndex
    gvReport.DataBind()
结束小组

I am using a GridView and I encountered the click twice on the Edit link to see the edit fields problem. Following advice I am binding my GridView again on the .RowEditing handler. The problem persist that I only see edit fields after my second click on any of the Edit links.

<%@ 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
解决方案

Found it. Needed to set the gridview's EditIndex and then do a databind.

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

这篇关于gridview的编辑,点击两次问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 09:09