加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – gridview编辑需要单击两次

发布时间:2020-12-16 07:44:31 所属栏目:asp.Net 来源:网络整理
导读:为什么在我的行进入编辑模式之前,我需要在gridview控件中单击编辑链接两次? asp:ObjectDataSource ID="ods" runat="server" TypeName="Employee"SelectMethod="GetAll" /asp:ObjectDataSource asp:GridView ID="GridView1" runat="server" CssClass="styled
为什么在我的行进入编辑模式之前,我需要在gridview控件中单击编辑链接两次?

<asp:ObjectDataSource ID="ods" runat="server" TypeName="Employee"
SelectMethod="GetAll"  ></asp:ObjectDataSource>

    <asp:GridView ID="GridView1" runat="server" CssClass="styled"  
    OnRowCommand="gv_RowCommand" DataSourceID="ods"
    OnSorting="gv_Sorting"  > 
    <Columns>
    ........... 
    </Columns> 
<ItemTemplate>
 <ItemTemplate>
<div class='actions'>
<asp:Button ID="btnEdit" runat="server" Text=" Edit " ToolTip="Edit Row" CommandName="Edit"  CommandArgument='<%# DataBinder.Eval(Container.DataItem,"Id") %>' CausesValidation="False" />
<span style="padding-left:10px"></span> 
</div>
</ItemTemplate>

    </asp:GridView>

  protected override void Page_Load(object sender,EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.ods.SelectParameters[0].DefaultValue = "";
            } 
        } 

protected void gv_RowCommand(object sender,GridViewCommandEventArgs e)
{
if (e.CommandName == CRUID.Edit.ToString())
{
    this.gv.ShowFooter = false;
}
}

解决方法

您需要避免在每次回发时重新绑定gridview.

If not ispostback then
    GridView1.DataSource = dt
    GridView1.DataBind()
end if

否则,您只需覆盖Gridview更改.

这个链接有很好的解释……
http://www.pcreview.co.uk/forums/gridview-two-clicks-needed-enter-place-editing-t3328887.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读