Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gridview edit requires to click twice

Why is that I need to click the edit link twice, in a gridview control, before my row enters into edit mode?

<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;
}
}
like image 313
Nick Kahn Avatar asked Nov 13 '22 20:11

Nick Kahn


1 Answers

You need to avoid rebinding your gridview on each postback.

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

Otherwise you just overwrite Gridview changes.

Great explanation at this link... http://www.pcreview.co.uk/forums/gridview-two-clicks-needed-enter-place-editing-t3328887.html

like image 142
htm11h Avatar answered Dec 08 '22 00:12

htm11h