gridView控件中的编辑链接不适用于第一次单击

时间:2015-06-04 09:01:34

标签: c# asp.net gridview

我在网格视图中提供了编辑选项。当我单击编辑链接时,它不会在第一次触发,但第二次正常工作。在这种情况下请帮帮我。我已经添加了标记,rowediting和page_load事件代码。

标记代码:

<asp:GridView ID="grdvwid" Width="100%" OnPageIndexChanging="page_changing" AllowPaging="true" AutoGenerateColumns="false" runat="server" Height="119px" onrowcancelingedit="grdvwid_RowCancelingEdit" onrowediting="grdvwid_RowEditing" onrowupdating="grdvwid_RowUpdating"
DataKeyNames="EXTERNAL_ID" onrowdatabound="grdvwid_RowDataBound">

    <SelectedRowStyle CssClass="gS" />
    <AlternatingRowStyle CssClass="gridAlternatingItemStyle1" />
    <RowStyle CssClass="gridItemStyle" />
    <HeaderStyle CssClass="gridheaderstyle" HorizontalAlign="Center"></HeaderStyle>
    <FooterStyle CssClass="gridheaderstyle"></FooterStyle>

    <Columns>
        <asp:CommandField ShowEditButton="true" HeaderText="Edit" ShowDeleteButton="false" CausesValidation="false" />
        <asp:BoundField HeaderText="id" ItemStyle-HorizontalAlign="Center" DataField="ID" SortExpression="ID" Visible="false" />
        <asp:BoundField HeaderText="Date Of Regi" ItemStyle-HorizontalAlign="Center" DataField="REGDATE" SortExpression="doc" ReadOnly="true" />
        <asp:BoundField HeaderText="Time" ItemStyle-HorizontalAlign="Center" DataField="COLTIME" SortExpression="coll_time">
            <ItemStyle Width="50" />
        </asp:BoundField>
        <asp:BoundField HeaderText="Pre_Registerd Time" ItemStyle-HorizontalAlign="Center" DataField="PRETIME" SortExpression="regtime" ReadOnly="true" />
    </Columns>

</asp:GridView>

grdvwid_RowEditing()的代码

protected void grdvwid_RowEditing(object sender, GridViewEditEventArgs e)
{
    grdvwid.PageIndex = e.NewEditIndex;
    bindgrid();
}

页面加载事件代码

private void Page_Load(object sender, System.EventArgs e) {
    try 
    {
        if (Session["UserName"] != null || Session["UserName"] != "") 
        {
            if (!IsPostBack) 
            {
                bindgrid();
                // query.  
            }
        }
        else 
        {
            Page.RegisterStartupScript("sessionmsg", "<script language=javascript>alert('Session Expired,Please Login to continue'); location.href('index.aspx');</script>");
        }
    } 
    catch (Exception ex) 
    {
        Page.RegisterStartupScript("sessionmsg", "<script language=javascript>alert('Session Expired,Please Login to continue'); location.href('index.aspx');</script>");
    }
}

0 个答案:

没有答案