开发者

Gridview edit, click twice problem

开发者 https://www.devze.com 2023-02-19 13:47 出处:网络
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

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>





    P开发者_Go百科ublic 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


Just call your grid binding function:

protected void GvEmployee_RowEditing(object sender, GridViewEditEventArgs e)
{
    GvEmployee.EditIndex = e.NewEditIndex;
    bindgridview();  // method of binding gridview
}
0

精彩评论

暂无评论...
验证码 换一张
取 消